PHP Classes

File: class_password-simple_example-test.php

Recommend this page to a friend!
  Classes of Sceptre   Quick And Easy Password Hashing   class_password-simple_example-test.php   Download  
File: class_password-simple_example-test.php
Role: Example script
Content type: text/plain
Description: simple example
Class: Quick And Easy Password Hashing
Create and verify password hashes with SHA and MD5
Author: By
Last change:
Date: 12 years ago
Size: 1,062 bytes


Class file image Download
//this example very simple, check the other one to see more

$password_raw = 'the password to hash';

$pwd = new Password();

//* gen new hash *
$password = $password_raw; //password provided by user
$hash = $pwd->hash($password); //hash the password
echo "The hash of the password is: <br />".$hash;
//$hash now contains the hashed pw, store this value in your db since we need it
//when the user wants to login again
//I will output the hash into a textbox for this example.

//this will validate the stored hash against the entered plain thext password
$db_hash = $hash; //retrieve previously generated hash. this should come from a database
$password = $password_raw; //password provided by user
$hash = $pwd->re_hash( $db_hash, $password ); //hash the entered password with the salt of db_hash
//if the entered pw is correct then $hash and the hash from your db must match exactly ===
if( $hash === $db_hash )
'<h1>Valid password</h1>';
'<h1>Invalid password</h1>';