Created
January 17, 2012 18:56
-
-
Save taytus/1628134 to your computer and use it in GitHub Desktop.
Password Hashing with Codeigniter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
public function createPassword($password,$username){
var_dump($password);
$user = array(