Skip to content

Instantly share code, notes, and snippets.

@taytus
Created January 17, 2012 18:56
Show Gist options
  • Save taytus/1628134 to your computer and use it in GitHub Desktop.
Save taytus/1628134 to your computer and use it in GitHub Desktop.
Password Hashing with Codeigniter
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;
}
}
@Pulemahoana
Copy link

public function createPassword($password,$username){

 $key = $this->config->item('encryption_key');
 $salt1 = hash('sha512', $key . $password);
 $salt2 = hash('sha512', $password . $key);
 $hashed_password = hash('sha512', $salt1 . $password . $salt2);

var_dump($password);
$user = array(

		   'password'=>$password,
		   'username'=>$username,
		   'user_id'=>$user_id
		   
		);


	$this->db->trans_start();
	$this->db->insert("login",$user);
	$user_id  = $this->db->insert_id();
	return $this->db->trans_complete();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment