Password Hashing in PHP

Functions for hashing password

  • password_hash()
  • password_verify()

password_hash() –

Syntax:

string $password – Password provide by user
integer $algo –   Password algorithm constant(PASSWORD_DEFAULT and PASSWORD_BCRYPT)
PASSWORD_DEFAULT – uses the BCrypt algorithm to create the hash
PASSWORD_BCRYPT –  uses the CRYPT_BLOWFISH algorithm and will return a 60 character string
$options – 
$options have two indexes.One is cost and another one is salt.
Cost-  Cost is the repetition of algorithm which have default value 10.  Which means algorithm will run 10 times to make a strong hash. You can configure your cost value according to your server configuration.
Syntax- 

password_verify() 

password_verify() used for checking a password against a password hash, then return a boolean.

Example –

Signup.php

index.php (login page)

How to run this script
1. Download and Unzip the file on your local system.
2. copy passwordhashing folder and put this file inside root directory(for xampp is htdocs,for wamp is www and for lamp is var/www/)
3. Database Configuration

Open phpmyadmin

http://localhost/phpmyadmin
Create Database pdosignup.
Import database pdosignup.sql(file available inside the pacakege)
Open Your browser put inside browser “http://localhost/passwordhashing /”

Download Source Code(Password Hashing)
Size: 7.53 KB
Version: V 1.0

 

Anuj Kumar

I'm Anuj kumar a web developer with 4+ year experience .I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to is provide php , jquery , mysql , phpoops and other web development tutorials. I am trying best effort to make PHPGurukul useful for every single moment spend on this website. If you think this website is useful to visit please share with your friend and buddies.

Recommended Tutorials for you

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *