Is it possible to use $_POST within sha1? or other encryption?

Asked

Viewed 81 times

1

I am comparing forms using sha1 as follows

sha1($_POST['txtEmpresa'] + $_POST['txtFornecedor'] + $_POST['txtDocumento'] + $_POST['txtValor'] + $_POST['txtVencimento']);

Is there any way to reduce this code to look like this?

sha1($_POST);

or another form of encryption that meets this need? I have used md5 and it didn’t work either.

2 answers

5


You can use the function implode(), but be careful with the variable $_POST can contain parameters that you do not want and this would lead to error.

Example:

sha1(implode('', $_POST));
  • "can count parameters that you do not want", I did not understand very well could explain me? I am using so sha1(date('Y-m-d H:m') + implode(', $_POST)) based on your statement and it worked.

  • 1

    Imagine that in the future you need to add one more field in the form that sends these POSTS, how would the comparison with the other sha1 that has ever been created before without this field? Do you realize there might be a difference? this is basically one of the concerns, but if this solved I am happy! don’t forget to mark the answer as solved :)

3

One possibility is you serialize $_POST content:

sha1(serialize($_POST));

And since you’re comparing the value of two Formulars, it might be interesting to use one ksort($_POST) before generating sha1 to ensure that the order of the fields is equal since this can change the hash value.

Browser other questions tagged

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