passwordspassword-protectionforgot-passwordpassword-storage

Is there a safe way to send a user their password in clear text via email?


If I understand correctly, the biggest problem with sending a password via email is that it requires the password to be stored in clear text in the database. If the DB is compromised, the attackers will gain access to all accounts.

Is there a workaround for this problem?

How can one make sending a user their password via email as safe as possible?


Solution

  • The simple answer is: don't. If you think your database is insecure, an email is far, far less.

    If you mean that you want to send them their password when they register, then you could do that before you store it in the database, but you shouldn't.

    If you mean after they have registered, the only option is to store in plaintext (again, don't do this) or make a new, random password and send them that. It is impossible to get their password from the hash, which is why it makes the password storage safer. The best option is to generate a new (temporary) password you send them, or a token giving them access to a password change system.

    You may want to consider a good hashing algorithm like BCrypt that includes a salt.