PHP Web Development

How to Salt & Hash a Password using Sha256

In last tutorial we learned password hashing in php. In this tutorial we will learn How to Salt & Hash a Password with Sha 256 in PHP.

Syntax for Sha256 encryption

Signup  form

A the time of  signup encrypt the password with Sha256    then insert in to database .

Login

Step1: Generate a random number

Step2: Encrypt the post password by using Sha256

Step3: Again Encrypt the Password with random number

Step4 : Fetch stored password  from database on the basis of username/email  and encrypt the password using sha256 with random number .

After that create a cost .You can configure your cost value according to your server configuration.By Default value is 10.

Step5: Hashig of the  post password

Step6: Now verify post hash password against stored password by using password_verify() function.

Here is the full code that we have written for login

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/pdologin/”

Download Source Code(How to Salt & Hash a Password using Sha256)
Size: 6.38 KB
Version: V 1.0

About the author

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.

Leave a Comment