tasks/includes/t-users/users.inc.php
Emmanuel BENOîT 9677ad4dd3 Initial import of tasks application
This initial import is a heavily modified version of the code I had
here, as Arse was modified for other purposes in the meantime and the
application no longer worked with it.

In addition:
 * I did not import the user management part yet,
 * task dependencies are supported in-base, but there is no interface
for that yet.
2012-02-05 18:47:04 +01:00

43 lines
842 B
PHP

<?php
class Dao_Users
extends DAO
{
private function hashPassword( $password , $salt , $iterations )
{
$hash = $password;
$salt = trim( $salt );
do {
$hash = sha1( "$salt$hash$salt" );
$iterations --;
} while ( $iterations > 0 );
return $hash;
}
public function getUser( $email )
{
$query = $this->query( 'SELECT * FROM users WHERE user_email = LOWER( $1 )' );
$results = $query->execute( $email );
if ( empty( $results ) ) {
return null;
}
return array_shift( $results );
}
public function checkLogin( $email , $password )
{
$userData = $this->getUser( $email );
if ( $userData != null ) {
$hashed = $this->hashPassword( $password ,
$userData->user_salt ,
$userData->user_iterations );
if ( $hashed === $userData->user_hash ) {
return $userData;
}
}
return null;
}
}