Skip to content

Commit f13dea2

Browse files
committed
Changes to login
-Limit Cookie length max 1 day -TWOFA_VALID_LENGTH needs to become switch name TBD -Logout also clear cookie -Included a not escapped IP in hash
1 parent 5e8f5c9 commit f13dea2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

web/login/index.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
function authenticate_user(){
3535
if(isset($_SESSION['token']) && isset($_POST['token']) && $_POST['token'] == $_SESSION['token']) {
3636
$v_user = escapeshellarg($_POST['user']);
37-
$v_ip = escapeshellarg($_SERVER['REMOTE_ADDR']);
37+
$ip = $_SERVER['REMOTE_ADDR'];
3838
if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){
3939
if(!empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
40-
$v_ip = escapeshellarg($_SERVER['HTTP_CF_CONNECTING_IP']);
40+
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
4141
}
4242
}
43+
$v_ip = escapeshellarg($ip);
4344
// Get user's salt
4445
$output = '';
4546
exec (HESTIA_CMD."v-get-user-salt ".$v_user." ".$v_ip." json" , $output, $return_var);
@@ -93,7 +94,7 @@ function authenticate_user(){
9394
exec (HESTIA_CMD . "v-list-user ".$v_user." json", $output, $return_var);
9495
$data = json_decode(implode('', $output), true);
9596
if ($data[$user]['TWOFA'] != '') {
96-
if(password_hash($data[$user]['TWOFA'].$_POST['murmur'],PASSWORD_BCRYPT) == $_COOKIE['limit2fa']){
97+
if(password_verify($data[$user]['TWOFA'].$ip.$_POST['murmur'],$_COOKIE['limit2fa'])){
9798

9899
}else{
99100
setcookie('limit2fa','',time() - 3600,"/");
@@ -116,10 +117,13 @@ function authenticate_user(){
116117
// Define session user
117118
$_SESSION['user'] = key($data);
118119
$v_user = $_SESSION['user'];
119-
if(empty($_COOKIE['limit2fa'])){
120-
setcookie('limit2fa',password_hash($data[$user]['TWOFA'].$_POST['murmur'],PASSWORD_BCRYPT),time()+60*60*24*$_SESSION['TWOFA_VALID_LENGTH'],"/");
120+
121+
//rename $_SESSION['TWOFA_VALID_LENGTH'] still to be done!
122+
if(empty($_COOKIE['limit2fa'] && $_SESSION['TWOFA_VALID_LENGTH'] == 1 && $data[$user]['TWOFA'] != "")){
123+
setcookie('limit2fa',password_hash($data[$user]['TWOFA'].$ip.$_POST['murmur'],PASSWORD_BCRYPT),time()+60*60*24,"/");
121124
};
122125
$_SESSION['LAST_ACTIVITY'] = time();
126+
123127
// Define language
124128
$output = '';
125129
exec (HESTIA_CMD."v-list-sys-languages json", $output, $return_var);

web/logout/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
} else {
88
session_destroy();
99
}
10-
10+
setcookie('limit2fa','',time() - 3600,"/");
1111
header("Location: /login/");
1212
exit;
1313
?>

0 commit comments

Comments
 (0)