how do i retrieve a md5 stored password

[php]{ // checking user is authorized…
// expects Base64 encoded version of ‘Basic jdoe:password’
$headers = apache_request_headers();
{ // checking that Authorization data has been supplied
if (empty($headers[‘Authorization’])) { // no credentials
$info->status = ‘failure’;
$info->error->code = 47;
$info->error->text = ‘Basic HTTP authentication required’;
$this->response($info, 401);
}
}
{ // checking to see if the Authorization string is valid
$this->load->database();
$sql = ‘SELECT COUNT(id) AS records FROM users ‘;
$sql .= ‘WHERE basic_http_auth = "’.$headers[‘Authorization’].’";’;
//$this->response($sql, 200);
$query = $this->db->query($sql);
$data = $query->row();
if ($data->records == “0”) {
$info->status = ‘failure’;
$info->error->code = 48;
$info->error->text = ‘Invalid credentials supplied’;
$this->response($info, 401);
}
}
}[/php]

i have this bit of php to check if the password matches but ive stored the password in mysql using md5 what would i need to change to check if the password matches?

The code you posted doesn’t do any type of password matching or retrieving.

yes i know its just checking to see if the user is authorised but ive stored the passwords in md5 how would i encrypt in sql to check if the users authorized.

TBH my question makes no sense as im totally confused. ??? ??? ???

There is a few examples here…

http://www.php.net/md5

Read the comments they show you have to do the database query for it.

Please change to something more secure than MD5, Bcrypt is a good choice as it’s the default password hashing method in PHP > 5.5

Sponsor our Newsletter | Privacy Policy | Terms of Service