Update and md5 password - encryption

I store the customers passwords in DB using encryption.
When the customer edits his personal data (including the password) the passwords are shown as *****
How can i understand that the use change his password so write to DB without encrypted again and again.
I mean that the value in password field is the encrypted value. If dont change the password must update with the same value (or not update at all)
If user change password to 1234 I must encrypt the 1234 and write to DB the encrypted value
Thanks

Don't send the md5 hashed string from the DB back. Set up three fields:
Old password
New password
New password again
Then check if the first field after md5 hashing is equal to the stored one in the DB. If it is, hash the second field and store it. (Only if the second and third is equal)

You should require entering both old and new password when user wants to change it.
That way, you can encode the old password, check if the encoded value is the same as in the database. If it is the same, then the you should update the password in db with encoded new password. If it is not the same (or old password is empty) you do not update.
This helps you to distinguish between password change and settings-only change. You also gain a some level of security, as if someone have captured the session of your user, he cannot change his password without also capturing is original password.

A few points:
MD5 is a hashing algorithm, you will never be able to reverse the hash and that's the point.
Don't use MD5 as it has been cracked, use an SHA2+ Hash Algorithm (SHA256 for example)
Simply confirm the password with the "old password" by hashing the old password against the one in the database.
Another option is resetting the password, which will email their confirmed (hopefully) contact email with the new password.
If they're logged into the system already, you should not need to "confirm" the old password again.
Never send the hashed password back from the database, it is kind of defeating the purpose of what you are trying to accomplish.

Related

[Symfony][FOSUserBundle] Can I get a user's former password

I'm using the FOSUserBundle on a Symfony project, and I would like to know if, when a user changes his password, I can have access to his former password. The one he's supposed to enter in the "current password" field.
I have a system of encryption on my project, and it's partially based on the user's password, that's why I need it, to update the user's encryption settings.
I created a listener when the user changes his password but I don't know how to get his former password. Or current password, whatever.
Thank you for your help !
Short answer: NO. If user won't give you his current password by typing it in form it's impossible to guess his password.
Only option to have access to current user's password is when password is stored in database in plain text which is rather not the case.
The way passwords are stored in db usually is by using hashing function which are designed to be impossible to invert - you are able to hash your password but you can't unhash it.
In theory you could try to use Rainbow tables but it's not something you could use in regular way on every passwprd change because it's very CPU heavy.
encrypt the new password.
compare the hash of the new password and the hash password in the database.

Obtain clear password from umbraco.cms.businesslogic.member

I need to send a mail to a umbraco user(member) with a password remind.
I work with umbraco.cms.businesslogic.member.Member class:
Member member = Member.GetMemberFromLoginName(userName);
string password = member.Password;
But when I look into this password apparently is a "coded"(crypted) password, not the "clear" one..
Is there a way to obtain a "clear" password ?
The passwords are hashed (and quite possibly salted) during account creation. The website doesn't know what the plaintext password is - it only can compare the hash (one-way cryptographic function, in theory irreversible) of what user inputed into password box with the stored hash.
The "forgot password" should verify owner of the account and send an e-mail with password reset link. Sending plaintext passwords emails is a huge security violation, as users often reuse their passwords on multiple sites, and gaining access to users email would expose password that can be tried on hundreds upon hundreds of different websites/systems.
Hopefully not.
It is very bad practice to store passwords in a way that allows for them to be recovered.
What you can do instead of "password reminder" is "password reset": Send them an email with a link that allows them to reset their password. Protected by some unique number that expires after a few hours and can only be used once.

how to get user password in decrypted format

I browse but didn't got proper solution.i am working on asp.net membership all i want to do is to retrieve user password when user apply for forgot password for condition 1. i want password to be in encrypted format in database and 2. retrieve password in decrypted format.is it possible.
Normally, encrypted passwords would be stored using a one way hash. This means
that the password cannot be decrypted once it is stored. Many authentication systems
work by taking the password ( of the user trying to authenticate ), encrypting
it using the same one way hash function as was used to store the password in the
database, and then doing a string comparison in order to determine if the
resulting encrypted password matches the one that exists in the database.
How are you determining if the user requesting the password is actually
the owner of the account ? Perhaps you can clarify your question with details
of the environment so that we may offer alternative solutions.
Use PasswordRecoveryControl
But anyhow it's not advisable to send password in plain text format.

How to convert text password to hashed password in wordpress

I have tried to convert a text password to hashed password by wp_hash_password() function.But the result password is not same as the password saved in wp_users table
$password = wp_hash_password($password);
I have also tried it by md5($password);
But generated password the not same as the password saved in wp_users table
The resuling hash is not supposed to be the same. Thats how the hashing was designed, Each stored password has a salt built in.
Wordpress uses Openwalls phpass (http://www.openwall.com/phpass/)
This makes it much more secure if there is a leak of the database as each row has its own salt so attacks are on a per password basis rather than a per database basis increasing the time taken for brute force and dictionary attacks etc.
Wordpress provide a function wp_check_password for checking a password agaist a hash.

Retrieving password when the password stored as a hash value

Can users request that their password be emailed to themselves if the password is stored as a hash value?
Is there any way to convert a hash value to the clear text value with the proper information (& what information would you need)?
If a user has the same password hash value stored on two sites, would their password be the same for both sites?
If you're only storing a hash of the password, then no. ...and you should only be storing a properly-salted hash of their password, anyway.
Password reset mechanisms are the proper alternative.
Hashed passwords cannot be retrieved in general (this depends on the hashing function, secure hashes cannot be retrieved). If they have the same hash on two sites, they could have the same password, this depends on the hash salt used by the sites, what method etc.
If your password is securely stored in a good hashing system, a provider should never be able to email you your password, you must reset your password if you forget it.
In short, no. With most hashing algorithms, you can have multiple inputs with the same output. It is often better to offer a password reset option.
There are different types of hashing algorithms. Some are more secure than others. MD5 is a popular, but insecure one. The SHA-family is another more secure set of algorithms.
By definition, a hash is a one way function. It can not be reversed.
http://en.wikipedia.org/wiki/Sha-1
If there was a simple way to recover the clear-text password, there would be no point in hashing the passwords to begin with. At that point you might as well just base64 or ROT13 them. (don't do that!)
As others mentioned, use other password recovery methods. There really is never a good reason to have access to clear-text passwords.
If the hash at two sites is the same, the user most likely has the same password at both. Not 100% guaranteed however, there could be a hash collision, but that is hugely improbable.
There is no way to reverse the commonly used hashes. They can be bruteforced (trying every single possible password) or you can use a wordlist (using a list of commonly used passwords) in combination to brute force to speed it up some, but it is still a very slow and CPU intensive process.
The best way, which many sites use, it to create a "Password Reset" button where you enter your username and email, and if they match, it sends you a random password and gives you a link to the login page and you can login with your random password and change your password.
To do this you must have a model with the fields:
Hashed_password
Salt
And you need to know the method user to hash the password( Here I use SHA1)
Then you can define in your controller:
def self.encrypted_password(password, salt)
string_to_hash = password + "wibble" + salt
Digest::SHA1.hexdigest(string_to_hash)
end
Next you can compare:
user.Hashed_password == encrypted_password(password, user.salt)
True means that "password" is the password for the user "user"
The general idea behind storing a hash of a password is to ensure the passwords are secure...even from those who have access to the database. Trust is never implicit. A hash is a one-way algorithm, so there is no way to derive the original password from a hashcode. Usually, when a user needs to recover their password that was stored as a hash, you should ask them their secret question, and either email them their temporary password, or email them a temporary link where they can change their password. This ensures that the password is never stored clear text, and is secure from all prying eyes, even those who might be assumed to be trustworthy.

Resources