I've had a look around around SO and found some useful info on using a hash, but not actually any information on how to use it with the StreamWriter
function in C#.
The code I used from SO was the code I found here: How to hash a password - Christian Gollhardt
CODE
private void Accept_Click(object sender, EventArgs e)
{
usrpass = usrpassTextbox.Text.ToString();
usrid = usridTextbox.Text.ToString();
if (FileExists() == true)
{
if (DialogResult.OK == MessageBox.Show("This user already exists, overwrite?", "Warning", MessageBoxButtons.OKCancel))
{
using (StreamWriter streamWriter = new StreamWriter(usrid + ".txt"))
{
streamWriter.WriteLine(usrpass);
MessageBox.Show(id + "'s password has been saved");
}
}
}
else
{
using (StreamWriter streamWriter = new StreamWriter(usrid + ".txt"))
streamWriter.WriteLine(usrpass);
MessageBox.Show(id + " " + "'s password has been saved");
}
}
}
Also I am considering putting the saving into a method to reduce code, I know there's no point in writing it out twice.
Desired Outcome
I would like the password that is being written to the .txt
file to be hashed, if this is hashed, will the user still be able to login when I write a bit of code that checks if the user's txt file exists, then reads it for the password?
Will I have to unhash it?
As of yet, I have the code I borrowed from Christian but not sure how to use it to hash the usrpass
before it is written to file