gPass

gPass Git Source Tree

Root/server/_user

1<?php
2/*
3 Copyright (C) 2013-2015 Grégory Soutadé
4
5 This file is part of gPass.
6
7 gPass is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 gPass is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with gPass. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21include("conf.php");
22
23function load_database()
24{
25 global $REQUESTS_MIN_DELAY;
26
27 try {
28 $db = new SQLite3("./gpass.bdd", SQLITE3_OPEN_READWRITE);
29 }
30 catch(Exception $e)
31 {
32 die("<b>Unable to load database for user $user !</b><br/>");
33 return null;
34 }
35
36 list($usec, $sec) = explode(" ", microtime());
37 $usec = $usec + $sec*1000;
38
39 try {
40 $last_time = $db->querySingle("SELECT last_access_time FROM conf");
41 if ($last_time <= $usec &&
42 ($usec - $last_time) < $REQUESTS_MIN_DELAY)
43 {
44 // Brute force ??
45 $db->close();
46 return null;
47 }
48 $db->query("UPDATE conf SET last_access_time=$usec");
49 $db->close();
50 $db = new SQLite3("./gpass.bdd", SQLITE3_OPEN_READONLY);
51 }
52 catch(Exception $e)
53 {
54 $db->close();
55 die("<b>Unable to load database for user $user !</b><br/>");
56 return null;
57 }
58
59 return $db;
60}
61
62$PROTOCOL_VERSION = 4;
63
64$db = load_database();
65
66$res = "";
67
68$statement = $db->prepare("SELECT password FROM gpass WHERE login=:login");
69
70echo "protocol=gpass-$PROTOCOL_VERSION\n";
71if ($PBKDF2_LEVEL != 1000)
72 echo "pbkdf2_level=$PBKDF2_LEVEL\n";
73
74for ($i=0; $i<$MAX_PASSWORDS_PER_REQUEST && isset($_POST["k$i"]); $i++)
75{
76 $statement->bindValue(":login", addslashes($_POST["k$i"]));
77 $result = $statement->execute();
78 $row = $result->fetchArray(SQLITE3_ASSOC);
79 $result->finalize();
80 if (isset($row["password"]))
81 {
82 echo "matched_key=" . $i . "\n";
83 echo "pass=" . $row["password"] . "\n";
84 break;
85 }
86}
87
88$statement->close();
89
90echo "<end>";
91
92?>

Archive Download this file