Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare md5 password php

Tags:

php

I need to check if $user_entered_passidential to $hash_val . Please help me?

    <?php
    $mypass = "Rainbow";
    $hash_val = md5($mypass);

    echo $hash_val; //always 32 characters

    $user_entered_pass = "rainbow";
?>
like image 741
Praba Avatar asked Jan 31 '26 21:01

Praba


1 Answers

You can hash $user_entered_pass and compare, I use this method.

<?php
    $mypass = "Rainbow";
    $hash_val = md5($mypass);

    echo $hash_val; //always 32 characters

    $user_entered_pass = "rainbow";

    if(md5($user_entered_pass) == $hash_val){
      //The passwords are equal
    }
?>
like image 98
Miguel Jiménez Avatar answered Feb 02 '26 10:02

Miguel Jiménez