How to salt a password using PowerShell and how to store the salt? - powershell

I was looking about how to salt a password in PowerShell, as SHA512 is not the safest way to store them, I want to add a salt to reduce bruteforcing.
Is there any way to add a salt to a password and then store it, to next at the moment on authenticate use the appropiate salt?

Related

How does a website know what salt to use when you try to login

For example let's say my password is "foo" and the website is using a md5 hash on passwords with a unique salt appended to it.
So when I register my password will be stored as "foo" with a salt appended to it and then md5 hashed.
Then when I send a login request the website will append a salt to "foo" and then md5 hash it, but how will the website know what the correct unique salt to use is?
How will the website magically know the correct unique salt to append to my password which is then md5 hashed, to verify the password I entered is equal to the md5 hashed salted password in the database?
This is the usual process of handling passwords:
User registers with a password.
A new data record is created for their user ID (which can come in the form of username or email, etc.)
Their password is handled:
A salt is generated for them, and that salt is saved in the data record. It's very common and recommended that the salt is visible right next to the password hash.
The password is combined with the salt (typically a library handles even this step for you, as any little nuance like appending salt matters a lot in security).
The password is hashed using a function designed for password hashing. This is usually quite computationally expensive to frustrate brute force attempts.
The password hash is stored in the data record, and the original password is discarded.
Then when they log in, there's no magic here:
The data record is looked up using their user ID.
The password they give is combined with the salt from the data record and then hashed.
If it matches the hash stored, they are granted access.
Some notes:
Password hashing is expensive. I don't think it's uncommon for it to take more than 1 whole second of computing time. Imagine the processing load if a thousand people are logging in at once.
A lot of things can go wrong if you aren't using a decent library to handle password hashing. Writing any of the steps yourself is not recommended.
It's common for libraries to output a coded string that contains everything you need to verify against a password, such as a version code, the hash, and the salt used.

when to hash a passwrd?

In my program I get the password into a variable (eg:string) and then before storing it into the database I hash it.Is that the correct and secured method?
Or should I hash it before storing it into a variable i.e. as soon as the user type in the password should it be hashed?
#Erina
Think about the purpose of hashing.
If someone breaks into your database they will not find passwords but only hashes which need to be brute forced into passwords in order to be useful.
By allowing the client to send a hash instead of the password you effectively make the hash the new password and all benefits are lost. i.e. if someone gets into the database they can instantly log into all accounts with the data they find there.
Therefore the client should always send the password and the server should do
the hashing.

How to decrypt hash password using C#?

I have a old database where password is in Hashed format,i need to decrypt hashed password.Is there any method in membership to decrypt hash password.
The hash is probably designed to be one way. If you know the hashing algorithm used you could use brute force, but otherwise no, there is no way to "decrypt" the password.

Legacy app with md5 hashes: how to add salt and SHA1?

I've a legacy app where passwords are hashed using MD5 without salt. I'd like to switch to SHA1 with salt, but I'd like to keep current users' passwords.
My plan is to change hashing function to sha1(md5(password) + salt). I'll be able to batch process all existing hashes using sha1(<existing_pass> + salt).
Is it safe to keep md5 in this case?
Is it ok to have one single salt for all users?
It's not a good idea to keep md5, read this question: Use SHA-512 and salt to hash an MD5 hashed password?.
It's better to have one salt for each user. With the same salt, users with the same password will have the same hash, and a rainbow table can be created for all your passwords at the same time.
As for question 1 I'm not quite sure but it seems to be OK.
For question 2: It is never OK to have same salt for all users. Salt has two functions. To prevent using pre-generated hashes / rainbow tables to search leaked database, and to prevent generation of dictionary-based hashes and searching databases with them too. Common salt will work in first case making rainbow tables unusable, but won't prevent cracker from dictionary attack. If cracker knows the global salt, he can generate frequent passwords, hash them and grep entire database. If salt is generated per user this scenario isn't possible.

What is the purpose of the "salt" when hashing?

Ok, I’m trying to understand the reason to use salt.
When a user registers I generate a unique salt for him/her that I store in DB. Then I hash it and the password with SHA1. And when he/she is logging in I re-hash it with sha1($salt.$password).
But if someone hacks my database he can see the hashed password AND the salt.
Is that harder to crack than just hashing the password with out salt? I don’t understand …
Sorry if I’m stupid …
If you don't use a salt then an attacker can precompute a password<->hash database offline even before they've broken into your server. Adding a salt massively increases the size of that database, making it harder to perform such an attack.
Also, once they've broken in they can guess a commonly used password, hash it, and then check all of the passwords in the database for a match. With a different salt for each user, they can only attack one password at a time.
There's an article at Wikipedia about salts in cryptography.
Another intention behind the use of a salt is to make sure two users with the same password won't end up having the same hash in the users table (assuming their salt are not the same). However, the combination of a salt and a password may lead to the same "string" or hash in the end and the hash will be exactly the same, so make sure to use a combination of salt and password where two different combination won't lead to the same hash.
If an attacker creates a giant table of hash values for plaintext passwords, using a salt prevents him from using the same table to crack more than one password. The attacker would have to generate a separate table for each salt. Note that for this to actually work propertly, your salt should be rather long. Otherwise the attacker's precomputed table is likely to contain the salt+password hash anyway.