| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | /* | 
					
						
							| 
									
										
										
										
											2015-12-04 17:02:31 +01:00
										 |  |  |   Copyright (C) 2013-2015 Grégory Soutadé | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  |    | 
					
						
							|  |  |  |   This file is part of gPass. | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   gPass is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |   it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |   the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |   (at your option) any later version. | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   gPass is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |   GNU General Public License for more details. | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |   along with gPass.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-21 19:00:26 +01:00
										 |  |  | include("conf.php"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  | function load_database() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-12-04 17:02:31 +01:00
										 |  |  |     global $REQUESTS_MIN_DELAY; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  |     try { | 
					
						
							| 
									
										
										
										
											2015-12-04 17:02:31 +01:00
										 |  |  |         $db = new SQLite3("./gpass.bdd", SQLITE3_OPEN_READWRITE); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     catch(Exception $e) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         die("<b>Unable to load database for user $user !</b><br/>"); | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     list($usec, $sec) = explode(" ", microtime()); | 
					
						
							|  |  |  |     $usec = $usec + $sec*1000; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |         $last_time = $db->querySingle("SELECT last_access_time FROM conf"); | 
					
						
							|  |  |  |         if ($last_time <= $usec && | 
					
						
							|  |  |  |         ($usec - $last_time) < $REQUESTS_MIN_DELAY) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Brute force ?? | 
					
						
							|  |  |  |             $db->close(); | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $db->query("UPDATE conf SET last_access_time=$usec"); | 
					
						
							|  |  |  |         $db->close(); | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  |         $db = new SQLite3("./gpass.bdd", SQLITE3_OPEN_READONLY); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     catch(Exception $e) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-12-04 17:02:31 +01:00
										 |  |  |         $db->close(); | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  |         die("<b>Unable to load database for user $user !</b><br/>"); | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-12-04 17:02:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  |     return $db; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-17 20:39:53 +02:00
										 |  |  | $PROTOCOL_VERSION = 4; | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | $db = load_database(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $res = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $statement = $db->prepare("SELECT password FROM gpass WHERE login=:login"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo "protocol=gpass-$PROTOCOL_VERSION\n"; | 
					
						
							| 
									
										
										
										
											2017-04-17 20:39:53 +02:00
										 |  |  | if ($PBKDF2_LEVEL != 1000) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     echo "pbkdf2_level=$PBKDF2_LEVEL\n"; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-04 17:02:31 +01:00
										 |  |  | for ($i=0; $i<$MAX_PASSWORDS_PER_REQUEST && isset($_POST["k$i"]); $i++) | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-02-09 18:57:49 +01:00
										 |  |  |     $statement->bindValue(":login", addslashes($_POST["k$i"])); | 
					
						
							| 
									
										
										
										
											2013-12-07 10:38:45 +01:00
										 |  |  |     $result = $statement->execute(); | 
					
						
							|  |  |  |     $row = $result->fetchArray(SQLITE3_ASSOC); | 
					
						
							|  |  |  |     $result->finalize(); | 
					
						
							|  |  |  |     if (isset($row["password"])) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         echo "pass=" . $row["password"] . "\n"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $statement->close(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo "<end>"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?> |