Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Encrypt and Decrypt password in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 752
    Comment on it

    We can easily encrypt and decrypt the password in php using the code below. First need to create key and string and pass it on to the encrypt function which are given below for encryption.

    $key = 'password for encrypt or decrypt';
    $string = ' string which requires for encryption ';
    

    For encrytion $var = mcrypt_create_iv( mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM );

    $encrypted = base64_encode(
        $var .
        mcrypt_encrypt(
            MCRYPT_RIJNDAEL_128,
            hash('sha256', $key, true),
            $string,
            MCRYPT_MODE_CBC,
            $var
        )
    );
    

    for Decryption

    $data = base64_decode($encrypted);
    $var = substr($data, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
    
    $decrypted = rtrim(
        mcrypt_decrypt(
            MCRYPT_RIJNDAEL_128,
            hash('sha256', $key, true),
            substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)),
            MCRYPT_MODE_CBC,
            $var
        ),
        "\0"
    );
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: