Skip to content

Instantly share code, notes, and snippets.

@syntaxseed
Last active September 30, 2023 13:19
Show Gist options
  • Save syntaxseed/37b3fbe65a4fa67879aa3ce1af130131 to your computer and use it in GitHub Desktop.
Save syntaxseed/37b3fbe65a4fa67879aa3ce1af130131 to your computer and use it in GitHub Desktop.
Legacy Password Hashing (Do not Use)
<?php
class PassHash {
//blowfish
private $algo = '$2a';
// cost paramter
private $cost = '$10';
private $salt = '';
//creates a salt
private function unique_salt() {
$this->salt = substr(sha1(mt_rand()),0,21); //sha1 hash a random number that takes the first 22 characters and stores the Hash in $hash
}
private function find_salt($hashed_password) {
$this->salt = substr($hashed_password, 7, 21);
}
// this will generate a hash
public function hash_password($password) {
$this->unique_salt();
return crypt( $password, $this->algo . $this->cost . '$' . $this->salt .'$' );
}
public function check_hash($raw_password, $hashed_password) {
$this->find_salt($hashed_password);
if (crypt($raw_password, $this->algo . $this->cost . '$' . $this->salt .'$') == $hashed_password){
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment