forked from justjanne/quassel-rest-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_functions.php
47 lines (39 loc) · 1.32 KB
/
auth_functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
//
// Quassel Backlog Search - classes
// developed 2009 by m4yer <[email protected]> under a Creative Commons Licence by-nc-sa 3.0
//
// password hashing improvements developed 2015 by mamarley
//
function initialAuthenticateUser($plainPassword,$dbHashedPassword,$hashVersion){
switch($hashVersion){
case null:
case 0:
return initialCheckHashedPasswordSha1($plainPassword,$dbHashedPassword);
break;
case 1:
return initialCheckHashedPasswordSha2_512($plainPassword,$dbHashedPassword);
break;
default:
return false;
break;
}
}
function initialCheckHashedPasswordSha1($plainPassword,$dbHashedPassword){
$calculatedPasswordHash=hash("sha1",$plainPassword);
if($calculatedPasswordHash==$dbHashedPassword){
return $calculatedPasswordHash;
}
return false;
}
function initialCheckHashedPasswordSha2_512($plainPassword,$dbHashedPassword){
$dbHashedPasswordArray=explode(":",$dbHashedPassword);
if(count($dbHashedPasswordArray)==2){
$calculatedPasswordHash=hash("sha512",$plainPassword . $dbHashedPasswordArray[1]);
if($calculatedPasswordHash==$dbHashedPasswordArray[0]){
return $dbHashedPasswordArray[0];
}
}
return false;
}
?>