MD5 is passing checks

Asked

Viewed 91 times

1

I have a problem when I use MD5 in my passwords, I have verification:

if(empty($regPassword)){
    exit('<div class="alert alert-danger margin-top15">&raquo; A <b>senha</b> é necessária e não pode ser vazia.</div>');
}

if(empty($regConfirmpass)){
    exit('<div class="alert alert-danger margin-top15">&raquo; <b>Confirmar a senha</b> é necessário e não pode ser vazio.</div>');        
}

When I use this in my variable:

$regPassword        = trim(strip_tags(md5($_POST['regPassword'])));
$regConfirmpass     = trim(strip_tags(md5($_POST['regConfirmpass'])));

The check doesn’t work someone knows why?

Complete code in: Here

  • 1

    Doesn’t work like? Here it worked by putting the same password.

  • It does not work to check if the user leaves the registration empty password field anyway.

  • 1

    It turns out that the function md5 will generate a hash in the same way, however it is a hash of an empty string.

  • 2

    trim and strip_tags are unnecessary in your code because the md5 will not return white spaces or tags

  • I withdrew and even so continues registering even leaving the input empty password, removed the md5 and the check worked, This weird I want it to work with MD5

  • You are checking before or after applying md5?

  • After applying md5 in the method $_POST

Show 2 more comments

1 answer

4


The function md5 generates a HASH, This is done with mathematical calculations on top of the string past. In case is generating a HASH and checking if it’s empty, sort of like this:

// md5('') == d41d8cd98f00b204e9800998ecf8427e (string)
if(empty('d41d8cd98f00b204e9800998ecf8427e')){

You need to check the user-informed variable:

if(empty($_POST['regPassword'])){
    exit('<div class="alert alert-danger margin-top15">&raquo; A <b>senha</b> é necessária e não pode ser vazia.</div>');
}

if(empty($_POST['regConfirmpass'])){
    exit('<div class="alert alert-danger margin-top15">&raquo; <b>Confirmar a senha</b> é necessário e não pode ser vazio.</div>');        
}
  • You solved my problem, but why did yours work and mine didn’t? I had already done exactly the same as you before.

  • 1

    Then I don’t know @Guilhermealves, I would have to see the code you made before to know... Need we are there... ;)

  • All right, I posted on Pastebin the code! Thanks a lot.

  • @Guilhermealves, you need to check the $_POST before to use the md5.

  • @Rafaelalmeida I have already solved with the answer of the Kaduamaral. but Thank you for trying to help me Rafael Almeida...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.