Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:55:56+00:00 2026-06-17T08:55:56+00:00

i am currently using md5 to authenticate users after they put their login email

  • 0

i am currently using md5 to authenticate users after they put their login email and password :

if($_POST['submit']=='Login')
{
    // Checking whether the Login form has been submitted

// Will hold our errors
$err = array();


if(!$_POST['email'] || !$_POST['main_password'])
    $err[] = 'All the fields must be filled in!';

if(!count($err))
{
    // Make this an integer.
    $_POST['rememberMe'] = (int)$_POST['rememberMe'];

    try {

        $sql = "SELECT id,email FROM ld_customers WHERE email = :cust_email AND password = :cust_password";
        $stmt = $iws_db->prepare($sql);


        $stmt->bindParam(':cust_email', $_POST['email'], PDO::PARAM_STR, 255);
        $stmt->bindParam(':cust_password', md5($_POST['main_password']) , PDO::PARAM_STR, 256);

        $stmt->execute();   
        $row = $stmt->fetch();

    if($row['email'])
    {

        // If everything is OK login and write the users data to the session.
        $_SESSION['email']=$row['email'];
        $_SESSION['id'] = $row['id'];
        $_SESSION['rememberMe'] = $_POST['rememberMe'];

        // Store some data in the session

        setcookie('iwsRemember',$_POST['rememberMe']);
    }

    else $err[]='Wrong email and/or password!';

    /*** close the database connection ***/
    $iws_db = null;
    }
    catch(PDOException $e)
    {
    echo $e->getMessage();
    }
}

if($err)
$_SESSION['msg']['login-err'] = implode('<br />',$err);
// Save the error messages in the session

header("Location: index.php");
    exit;
}

but i want to now authenticate using PBKDF2 by https://defuse.ca/php-pbkdf2.htm.Here is the snippet of code by them:

    <?php

define("PBKDF2_HASH_ALGORITHM", "sha256");
define("PBKDF2_ITERATIONS", 10000);
define("PBKDF2_HASH_BYTES", 24);
define("PBKDF2_SALT_BYTES", 24);

define("HASH_SECTIONS", 4);
define("HASH_ALGORITHM_INDEX", 0);
define("HASH_ITERATION_INDEX", 1);
define("HASH_SALT_INDEX", 2);
define("HASH_PBKDF2_INDEX", 3);

function create_hash($password)
{
    // format: algorithm:iterations:salt:hash
    $salt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTES, MCRYPT_DEV_URANDOM));     
    return PBKDF2_HASH_ALGORITHM . ":" . PBKDF2_ITERATIONS . ":" .  $salt . ":" . 
        base64_encode(pbkdf2(
            PBKDF2_HASH_ALGORITHM,
            $password,
            $salt,
            PBKDF2_ITERATIONS,
            PBKDF2_HASH_BYTES,
            true
        ));
}

function validate_password($password, $good_hash)
{
    $params = explode(":", $good_hash);
    if(count($params) < HASH_SECTIONS)
       return false; 
    $pbkdf2 = base64_decode($params[HASH_PBKDF2_INDEX]);
    return slow_equals(
        $pbkdf2,
        pbkdf2(
            $params[HASH_ALGORITHM_INDEX],
            $password,
            $params[HASH_SALT_INDEX],
            (int)$params[HASH_ITERATION_INDEX],
            strlen($pbkdf2),
            true
        )
    );
}




function slow_equals($a, $b)
{
    $diff = strlen($a) ^ strlen($b);
    for($i = 0; $i < strlen($a) && $i < strlen($b); $i++)
    {
        $diff |= ord($a[$i]) ^ ord($b[$i]);
    }
    return $diff === 0; 
}

function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
{
    $algorithm = strtolower($algorithm);
    if(!in_array($algorithm, hash_algos(), true))
        die('PBKDF2 ERROR: Invalid hash algorithm.');
    if($count <= 0 || $key_length <= 0)
        die('PBKDF2 ERROR: Invalid parameters.');

    $hash_length = strlen(hash($algorithm, "", true));
    $block_count = ceil($key_length / $hash_length);

    $output = "";
    for($i = 1; $i <= $block_count; $i++) {
        // $i encoded as 4 bytes, big endian.
        $last = $salt . pack("N", $i);
        // first iteration
        $last = $xorsum = hash_hmac($algorithm, $last, $password, true);
        // perform the other $count - 1 iterations
        for ($j = 1; $j < $count; $j++) {
            $xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
        }
        $output .= $xorsum;
    }

    if($raw_output)
        return substr($output, 0, $key_length);
    else
        return bin2hex(substr($output, 0, $key_length));
}
?>

i tried doing implementing this in this way:

  if($_POST['submit']=='Login')
    {
        // Checking whether the Login form has been submitted

    // Will hold our errors
    $err = array();


    if(!$_POST['email'] || !$_POST['main_password'])
        $err[] = 'All the fields must be filled in!';

    if(!count($err))
    {
        // Make this an integer.
        $_POST['rememberMe'] = (int)$_POST['rememberMe'];

        try {

            $sql = "SELECT id,email FROM ld_customers WHERE email = :cust_email";
        $stmt = $iws_db->prepare($sql);

        /*** bind the paramaters ***/
        $stmt->bindParam(':cust_email', $_POST['email'], PDO::PARAM_STR, 255);




        $stmt->execute();

        $row = $stmt->fetch();

                    if(!validate_password($_POST['main_password'], $row['password']))
                    {
                     exit("Password error!");
                    }
                     else
                    {
                     if($row['email'])
             {
              // If everything is OK login and write the users data to the session.
        $_SESSION['email']=$row['email'];
        $_SESSION['id'] = $row['id'];
        $_SESSION['rememberMe'] = $_POST['rememberMe'];

        // Store some data in the session

        setcookie('iwsRemember',$_POST['rememberMe']);    

        }
                    else
                    {
                    $err[]='Wrong email and/or password!';
                    }
                   }


    /*** close the database connection ***/
    $iws_db = null;
    }
    catch(PDOException $e)
    {
    echo $e->getMessage();
    }
}

if($err)
$_SESSION['msg']['login-err'] = implode('<br />',$err);
// Save the error messages in the session

header("Location: index.php");
exit;

i am not successful implementing it, every time it exit saying password error!! i think the problem is fetching the stored encrypted password and comparing it with password input by user.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:55:56+00:00Added an answer on June 17, 2026 at 8:55 am

    I think it should be something like:

        $sql = "SELECT id,email FROM ld_customers WHERE email = :cust_email";
        $stmt = $iws_db->prepare($sql);
    
    
        $stmt->bindParam(':cust_email', $_POST['email'], PDO::PARAM_STR, 255);
    
        $stmt->execute();   
        $row = $stmt->fetch();
    if($row['email'])
    {
      if(!validate_password($_POST['main_password'], $row['password']))
      {
         exit("Password error!");
      }
      else
      {
        echo'Logged in!';
      }
    }
    else
       echo"email doesn't exist";
    

    You are creating an MD5 hash instead of using the functions of your library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently use phpBB to authenticate users to pages outside of their bulletin board
I'm currently using MD5 and SHA1 to save my users' passwords in a database
I am currently using md5 function to encrypt my password and save to mysql
I am currently using MD5 encryption for storing the password in the database. We
Greetings, I have some mysql tables that are currently using an md5 hash as
I'm currently using this code for md5 hashing in Delphi 7: function MD5(const fileName
I am currently creating application using Java, I googled password encryption with java but
So currently my code is using a standard sha1 to hash the password for
Currently using the HTTPServletRequest class and specifically the .getQueryString method to retrieve an inputted
Currently using Google Analytics as a supplement to our paid tracking software, but neither

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.