Skip to content

Commit 3ee0224

Browse files
authored
Fix password error
added a check for password hashing to avoid doble hashing or non-hashing of the password that turns into error login.
1 parent 0d167a1 commit 3ee0224

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

app/functions/functions.user.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,17 @@ public static function AddUser($userData)
568568
$userData['oauth_token'] = '';
569569
}
570570
if (!isset($userData['password']) || nullval($userData['password'])) {
571-
$userData['password'] = '';
571+
$upassword = '';
572+
} else {
573+
$upassword = $userData['password'];
574+
if(preg_match('/^[0-9a-f]{40}$/i', $upassword)){
575+
/* already encrypoted with sha1 */
576+
$upassword = toDb($upassword);
577+
} else {
578+
$upassword = sha1($upassword);
579+
}
572580
}
581+
573582
if (!isset($userData['local']) || nullval($userData['local'])) {
574583
$userData['local'] = '';
575584
}
@@ -581,7 +590,7 @@ public static function AddUser($userData)
581590
}
582591
//insert to db
583592
$sql = "INSERT INTO " . DB_PREFIX . "users (name,username,email,type,lastlogin,date_registered,gid,fid,oauth_token,avatar,local,country,group_id,pass,password,bio)"
584-
. " VALUES ('" . toDb($userData['name']) . "','" . toDb($userData['username']) . "','" . esc_attr($userData['email']) . "','" . $userData['type'] . "', now(), now(), '" . $userData['gid'] . "', '" . $userData['fid'] . "', '" . $userData['oauth_token'] . "', '" . $userData['avatar'] . "', '" . toDb($userData['local']) . "', '" . toDb($userData['country']) . "', '4', '" . $pass . "','" . toDb($userData['password']) . "', '" . toDb($userData['bio']) . "')";
593+
. " VALUES ('" . toDb($userData['name']) . "','" . toDb($userData['username']) . "','" . esc_attr($userData['email']) . "','" . $userData['type'] . "', now(), now(), '" . $userData['gid'] . "', '" . $userData['fid'] . "', '" . $userData['oauth_token'] . "', '" . $userData['avatar'] . "', '" . toDb($userData['local']) . "', '" . toDb($userData['country']) . "', '4', '" . $pass . "','" . $upassword . "', '" . toDb($userData['bio']) . "')";
585594
$db->query($sql);
586595
$tid = user::checkUser($userData);
587596
return $tid;
@@ -781,4 +790,4 @@ function getUserName($id)
781790
return '';
782791
}
783792

784-
?>
793+
?>

0 commit comments

Comments
 (0)