Skip to content

Commit 8fdc9d9

Browse files
author
Kristan Kenney
committed
Merge branch 'fix/2020-10-hash_rkey' into staging/fixes
2 parents e2e40d3 + 91447e4 commit 8fdc9d9

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

bin/v-change-user-rkey

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
2-
# info: change user password
3-
# options: USER
2+
# info: change user random key
3+
# options: USER [HASH]
44
#
5-
# The function changes user's password and updates RKEY value.
5+
# The function changes user's RKEY value thats has been used for security value to be used forgot password function only.
66

77

88
#----------------------------------------------------------#
@@ -11,8 +11,9 @@
1111

1212
# Argument definition
1313
user=$1
14+
hash=$2
1415

15-
16+
echo $rkeyhash;
1617
# Importing system enviroment as we run this script
1718
# mostly by cron wich not read it by itself
1819
source /etc/profile
@@ -25,14 +26,21 @@ source $HESTIA/conf/hestia.conf
2526
# Verifications #
2627
#----------------------------------------------------------#
2728

28-
check_args '1' "$#" 'USER'
29+
check_args '1' "$#" 'USER [HASH]'
2930
is_format_valid 'user'
3031
is_object_valid 'user' 'USER' "$user"
3132
is_object_unsuspended 'user' 'USER' "$user"
3233

3334
# Perform verification if read-only mode is enabled
3435
check_hestia_demo_mode
3536

37+
if [ ! -z "$hash" ]; then
38+
password=$hash
39+
is_password_valid
40+
hash=$password;
41+
else
42+
hash=$(generate_password)
43+
fi
3644
#----------------------------------------------------------#
3745
# Action #
3846
#----------------------------------------------------------#
@@ -44,7 +52,7 @@ d=$(date +%s)
4452
#----------------------------------------------------------#
4553

4654
# Changing RKEY value
47-
update_user_value "$user" '$RKEY' "$(generate_password)"
55+
update_user_value "$user" '$RKEY' "$hash"
4856

4957
#check if RKEYEXP exists
5058
if [ -z "$(grep RKEYEXP $USER_DATA/user.conf)" ]; then

web/reset/index.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@
2020
$data = json_decode(implode('', $output), true);
2121
if($email == $data[$user]['CONTACT']){
2222
//genrate new rkey
23-
exec ("/usr/bin/sudo /usr/local/hestia/bin/v-change-user-rkey ".$v_user."", $output, $return_var);
23+
$rkey = substr( password_hash( 'hestiacp', PASSWORD_DEFAULT ), 5, 12 );
24+
$hash = password_hash($rkey, PASSWORD_DEFAULT);
25+
$v_rkey = tempnam("/tmp","vst");
26+
$fp = fopen($v_rkey, "w");
27+
fwrite($fp, $hash."\n");
28+
fclose($fp);
29+
exec ("/usr/bin/sudo /usr/local/hestia/bin/v-change-user-rkey ".$v_user." ".$v_rkey."", $output, $return_var);
2430
unset($output);
2531
exec ($cmd." ".$v_user." json", $output, $return_var);
2632
$data = json_decode(implode('', $output), true);
27-
$rkey = $data[$user]['RKEY'];
2833
$name = $data[$user]['NAME'];
2934
$contact = $data[$user]['CONTACT'];
3035
$to = $data[$user]['CONTACT'];
@@ -58,7 +63,7 @@
5863
if ( $return_var == 0 ) {
5964
$data = json_decode(implode('', $output), true);
6065
$rkey = $data[$user]['RKEY'];
61-
if (hash_equals($rkey, $_POST['code'])) {
66+
if (password_verify($_POST['code'], $rkey)) {
6267
unset($output);
6368
exec("/usr/bin/sudo /usr/local/hestia/bin/v-get-user-value ".$v_user." RKEYEXP", $output,$return_var);
6469
if($output[0] > time() - 900){

0 commit comments

Comments
 (0)