abhik143 Posted July 22, 2016 Share Posted July 22, 2016 Hiii, I want to save a password in encrypted form, so that it will not be understand by human. Is it possible ? If yes then please explain briefly. Quote Link to comment https://forums.phpfreaks.com/topic/301539-in-php-how-to-save-a-password-in-encrypted-form/ Share on other sites More sharing options...
requinix Posted July 22, 2016 Share Posted July 22, 2016 First, you want hashing. Encryption is when you can get the original password back from your database. That sounds good but it isn't. What you need is hashing, which is taking something like a password and turning it into another thing that looks random but will give you the same result for the same password. (Basically.) Then you compare hashes. Use password_hash and password_verify like // when setting or changing a password $hash = password_hash($_POST["password"]); /* put $hash in the database */ // when checking a password if (password_verify($_POST["password"], $hash_from_database)) { // password matches } else { // password does not match } Quote Link to comment https://forums.phpfreaks.com/topic/301539-in-php-how-to-save-a-password-in-encrypted-form/#findComment-1534814 Share on other sites More sharing options...
Jacques1 Posted July 22, 2016 Share Posted July 22, 2016 password_hash() requires an algorithm and should be called with specific parameters: <?php const PW_HASH_ALGORITHM = PASSWORD_BCRYPT; // bcrypt is the de-facto standard and currently the only choice const PW_HASH_COST = 14; // adjust this to your own needs $password = 'test'; $hash = password_hash($password, PW_HASH_ALGORITHM, ['cost' => PW_HASH_COST]); var_dump($hash); Quote Link to comment https://forums.phpfreaks.com/topic/301539-in-php-how-to-save-a-password-in-encrypted-form/#findComment-1534815 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.