Skip to content

Instantly share code, notes, and snippets.

@cam-gists
Forked from taytus/password_hashing.php
Created July 13, 2012 21:04
Show Gist options
  • Save cam-gists/3107443 to your computer and use it in GitHub Desktop.
Save cam-gists/3107443 to your computer and use it in GitHub Desktop.
PHP: Codeigniter: Password Hash
function new_registration($username, $email, $password, $confirmation_code)
{
// Store the new user's information in the database.
$key = $this->config->item('encryption_key');
$salt1 = hash('sha512', $key . $password);
$salt2 = hash('sha512', $password . $key);
$hashed_password = hash('sha512', $salt1 . $password . $salt2);
$userinfo = array(
'username' => $username,
'email' => $email,
'password' => $hashed_password,
'confirmation_code' => $confirmation_code
);
$this->db->insert('user', $userinfo);
}
function check_login_exists($username, $password)
{
$key = $this->config->item('encryption_key');
$salt1 = hash('sha512', $key . $password);
$salt2 = hash('sha512', $password . $key);
$hashed_password = hash('sha512', $salt1 . $password . $salt2);
$query_active = $this
->db->where('username', $username)
->where('password', $hashed_password)
->limit(1)
->get('user');
if ($query_active->num_rows > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment