Password Hashing in PHP

5

- Advertisement -

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

    - Advertisement -

    Leave A Reply

    Your email address will not be published.

    5 Comments
    1. Charles says

      Hi Anuj,
      If a user forgot his password or wants to change it, how should it be integrated from the login menu?
      Thank You for this tutorial.

      1. Anuj Kumar says

        I will upload the tutorial for forgot password soon.

    2. Akash says

      How to decrypt this ?

      1. Anuj Kumar says

        You can’t decrypt the password. You can only verify the password.

        1. Pastor David says

          Thank you so much. I too, I’m training people on webdesign free tuition fees.
          I love you. Be bless.

    Leave A Reply

    Your email address will not be published.