How to use sha256 in php5.3.0

后端 未结 5 1769
时光取名叫无心
时光取名叫无心 2021-02-01 01:32

I\'m using sha256 to encrypt the password. I can save the sha256 encrypted password in mysql. But i can\'t login with the same clause.

Insert code:



        
5条回答
  •  既然无缘
    2021-02-01 01:54

    First of all, sha256 is a hashing algorithm, not a type of encryption. An encryption would require having a way to decrypt the information back to its original value (collisions aside).

    Looking at your code, it seems it should work if you are providing the correct parameter.

    • Try using a literal string in your code first, and verify its validity instead of using the $_POST[] variable

    • Try moving the comparison from the database query to the code (get the hash for the given user and compare to the hash you have just calculated)

    But most importantly before deploying this in any kind of public fashion, please remember to sanitize your inputs. Don't allow arbitrary SQL to be insert into the queries. The best idea here would be to use parameterized queries.

提交回复
热议问题