I have a user table, each user has a password, and a password salt.
I want to reset every user password using a sql script, but I need to know which hash is used for password, here is an example:
pass : $2y$10$WjgvLQbIyx4Oab69b2vEKuOPafgWC2yzWD7JqYvC6dgvjW2iuNi/m
password salt: AF7
It looks as if the hashed password was generated with the PHP function password_hash.
The $2y$10$ at the beginning seems to indicate that the default algorithm was used (second parameter):
password_hash(password, PASSWORD_DEFAULT)
I hope you didn't use "AF7" as a salt for all passwords. That would completely defeat its purpose. It's the same as using no salt at all.
When setting new passwords, it's not relevant what hashing function was originally used. Instead, it's important what's used to verify the password. I assume that PHP's password_verify function is used. So you can easily use a different algorithm and a random salt. It's all encoded in the string that's stored in the database and password_verify will be able to handle it.
That looks like a hash generated by a method such as password_hash, bcrypt or a similar method.
Hashes are not encryption, they one-way functions designed not to be reversible, information is lost, by design, in the hashing function.
Related
Nowdays, technology changes faster. Could you please give me best technique to protect a password from contact form?
I read about functions as MD5, SHA1 but I don't know what the best options.
The idea is protect password from Javascript. Then, get value in PHP and save it in database.
Any recomendations ?
Thanks
Password hashing must be done server-side, client-side hashing can be done, but never replaces server side hashing.
With PHP you should use the function password_hash(), currently it uses the BCrypt algorithm. Never use MD5 or SHA-* to hash passwords, those algorithms are way too fast and can be brute-forced too easily.
// Hash a new password for storing in the database.
// The function automatically generates a cryptographically safe salt.
$hashToStoreInDb = password_hash($password, PASSWORD_DEFAULT);
// Check if the hash of the entered login password, matches the stored hash.
// The salt and the cost factor will be extracted from $existingHashFromDb.
$isPasswordCorrect = password_verify($password, $existingHashFromDb);
Normally a password is stored with a one-way algorithm, so that it makes hard to discover the plain text from it.
But I've been thinking: What if I store a SHA512 of both username and password melted together (A+B=SHA512), instead of the username and the password hash separately.
Is this method secure?
EDIT: In my opinion the Username 'salt' the password, so there will be no equal hash two times...
(1) You should be using something like bcrypt, scrypt, or pbkdf2 instead of something like SHAwhatever for password processing. Google this.
(2) How would you deal with forgotten password scenario?
(3) See my blog, particularly the section on "A simple example: protecting email address": https://littlemaninmyhead.wordpress.com/2015/09/08/a-retrospective-on-ashely-madison-and-the-value-of-threat-modeling/
Sure that would work. But would you ever want to retrieve a list of user names?
In the authentication implementations I have written, I use the username as part of the salt. That combined with a sitewide salt plus a bit of constant salt ends up creating around 120 bits of salt per username.
Is there a way to do this?
In my mapping class, I want to decrypt a MD5 password when I fetch my database data into entities. Is this possible?
Thank you!
MD5 can be used to encrypt passwords. MD5 is considered as a broken. What you do is you hash the password with MD5 and compare it with the original hash value in the database. Since MD5 is one way, if the passwords are same, hash value is same.
Edit:
If you are looking for cracking MD5 encrypted passwords, That is something different. Take a look at this
You mist first understand that this is not technology specific. These are basic computer science generic concepts which can be used implemented using various technologies. In you case C# and NHibernate etc.
To be simple, what you are doing with MD5(Message-Digest algorithm 5) is, you do hashing. because it is a hashing function. take a look at this.
But this MD5 is a one way hash function. "one way" means that it's nearly impossible to derive the original text from the string. That is why it is used for password encryption. Because you can not reverse a one way function and get the actual password. Take a look at this as well.
I assume that you want to check weather the inserted password is correct and allow log-in or do what ever necessary. You should not be doing decryption a password. If you are not going to crack a password. Password cracking is more of a guessing and scope can be reduced using the weaknesses of implemented methodologies(In MD5 hashing collisions).
In password creation, you take the password and you hash it using MD5(in your case).Then this hash value is what you are going to store in a database. Then next time you want to check weather the password is correct. Then you again take the password and you again hash it using MD5. then you take that hash value and compare it with the hash value in the database. If they match inserted password is correct.
I can see that you are new to SO. What I recommend is that you better learn these concepts first and the these concepts will help you irrespective of what technology you use.
You might as well ask if you can turn a pile of ashes back into the log before it was burned. Hashing is a one way action... you cannot "reverse" it. The only thing you could do is determine some source values that generate the same hash (hash collision).
I'm trying to secure a website that is being moved to a public server soon. I've just finished adding the password hashing functions to all of my login scripts. I'm using FormsAuthentication.HashPasswordForStoringInConfigFile(pw, method) to do so. I have a question about the process I'm using and whether or not it's secure for a web server:
Password is sent in plain text over HTTPS to the server
The server looks in the Users table to find the user's Salt (several random characters) and their hashed and salted stored password
The plain text password is appended with the Salt
The new string is hashed using the above function
The newly hashed version is compared to the stored version
If equal, login is allowed
If not equal, the login attempt is logged in Session variables, up to 3 times before locking out the user's machine from accessing the login page until an admin verifies IP address and unlocks.
Does this look about right? I just don't see how the salt is effective in this method... Anyway, all I've done is add a salt and hash. Is this considered Encryption? Or am I missing a step? I remember reading that hashing algorithms like SHA1 and MD5 are not encyption algorithms, so what else needs to be done?
That is correct. The salt is used to prevent rainbow table attacks where a dictionary of common works hashed with MD5 is used to try to gain entry. Using the salt ensures that even if they had an MD5 hash of the word, it wouldn't work because they don't know the salt.
The MD5 algorithm is a 1 way hash algorithm, and not an encryption value. The difference is, once you've hashed the value, there is no way to get back to the original value. Encryption allows you to decrypt the data and get back the original value. So you are correct, they are not the same, and your passwords are not encrypted, they are hashed. This means that if someone forgets their password, you cannot send it to them. You have to provide a way for them to reset their password instead. This also means that anyone with access to the database would not have access to raw passwords. Which is good because a lot of people use the same password everywhere, and if you had access to a large list of usernames and passwords, someone could decide to start trying to log into bank / credit card websites.
What you are doing is a recommended practice.
You shouldn't be storing the retry count in the session - an attacker could simply discard their session cookie after each attempt, allowing them to retry as many times as they wish. Instead, store it against the user record.
hey guys,
i want to hash the password so it is totally encrypted, i am able to hash the password, but now the issue is i am not able to again get back the real password, is there any way i can get the real password using any of the hash, or is there any other way to encrypt and also decrypt the text into its original content...
Please reply as soon as possible..
Thanks and regards
abbas electricwala.
Hash is a one way encryption - that's the point - not to be able to get the original information from it. Hash is meant for verifying integrity. You can check if a entered string is the correct password by hashing and comparing the hashes with the one you had before.
The whole point of hashing a password is so that you do not have to save passwords in clear text. If someone can get the hashed passwords, he can't convert them back to passwords. Also, don't forget to salt your hashing otherwise your hashed passwords are vulnerable to rainbow tables.
Hashing isn't encryption, you cannot reverse it. You use hashing to check whether someone has a specific password, without knowing the password yourself.
The idea of hash functions is, to make it impossible to reconstruct the orignal data from the hash. Furthermore there are infinite different inputs to a hash function giving the same result.
If you want to check if a password entered in, say a login form matches the valid passwort, hash the newly input password and compare the hashes.
You typically can't and shouldn't. You also hash the received password and compare the two hashes
Theoretically once the data is converted using a one-way hash function, the hashed version of the data cannot be used to recreate the original data.
You may want to try a brute force attack against the hash code, using a dictionary. It naturally helps if you know which hash function has been used.