Skip to content

Commit

Permalink
Refactoring: Simplified debugging and updating of password hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
evaK-de committed Jan 5, 2017
1 parent 2849b13 commit ce50c22
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions include/class.user.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class user {
function add($name, $email, $company, $pass, $locale = "", $tags = "", $rate = 0.0)
{
global $conn,$mylog;
$pass = sha1($pass);
$hash = $this->hash($pass);

$ins1Stmt = $conn->prepare("INSERT INTO user (name,email,company,pass,locale,tags,rate) VALUES (?, ?, ?, ?, ?, ?, ?)");
$ins1 = $ins1Stmt->execute(array($name, $email, $company, $pass, $locale, $tags, $rate));
$ins1 = $ins1Stmt->execute(array($name, $email, $company, $hash, $locale, $tags, $rate));

if ($ins1) {
$insid = $conn->lastInsertId();
Expand Down Expand Up @@ -274,6 +274,18 @@ function getAvatar($id)
}
}

/**
* Returns a hash of the password.
*
* @param $password
* @return string
*/
function hash($password) {
$hashedPassword = sha1($password);

return $hashedPassword;
}

/**
* Log a user in
*
Expand All @@ -289,9 +301,9 @@ function login($user, $pass)
return false;
}
$user = $conn->quote($user);
$pass = sha1($pass);
$hash = $this->hash($pass);

$sel1 = $conn->query("SELECT ID,name,locale,lastlogin,gender FROM user WHERE (name = $user OR email = $user) AND pass = '$pass'");
$sel1 = $conn->query("SELECT ID,name,locale,lastlogin,gender FROM user WHERE (name = $user OR email = $user) AND pass = '$hash'");
$chk = $sel1->fetch();
if ($chk["ID"] != "") {
$rolesobj = new roles();
Expand Down

0 comments on commit ce50c22

Please sign in to comment.