Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display salted password as a string

Tags:

php

I have a piece of code below where it echos a salted password:

            $pass = rand();
            $pass = md5($pass);
            $pass = substr($pass, 0, 15);
            $pass = md5(md5("g3f".$pass."rt4")); 

Now if I echo $pass, then it will output this for example:

8723d9c8a8b2af798be25fd07ab0ff0a 

But what I want to do is echo the password itself so that for example instead of displaying the above it will display the string which is "password".

How can this be achieved?

Thanks

like image 479
user1723760 Avatar asked Dec 26 '22 16:12

user1723760


1 Answers

You can't. Hashing is a one way street. If you want to hide a string that needs to be shown later, you'd need to use encryption instead. However, this is a taboo when it comes to passwords.

To address the second part of the question, you should NEVER send user passwords via email. Implement a server-side solution (for instance use security questions + verification of their email) and after authentication allow users to change their passwords directly on the website.

Oh, and one more thing - forget about MD5!!!!

like image 92
walther Avatar answered Jan 09 '23 21:01

walther