I am currently working on a Log in form but the thing here is that when I enter an invalid username this errors comes up.
Invalid length for a Base-64 char array.
On this line of code:
bool isSame = hasher.CompareStringToHash(txtPassword.Text, hashedPassword);
Here is the full code
public void verifyAccount()
{
var hashedPassword = getPassword();
var hasher = new Hasher();
hasher.SaltSize = 16;
bool isSame = hasher.CompareStringToHash(txtPassword.Text, hashedPassword);
if (isSame==false)
{
MessageBox.Show("Invalid UserName or Password");
}
else
{
MainWindow main = new MainWindow();
this.Hide();
main.ShowDialog();
this.Close();
}
}
And the This is the method for searching a such username at the same time getting their password password in the database.
public string getPassword()
{
DataClasses1DataContext myDbContext = new DataClasses1DataContext(dbPath);
var password = (from user in myDbContext.Accounts
where user.accnt_User == txtUser.Text
select user.accnt_Pass).FirstOrDefault();
if (password == null) {
return "z";
}
return password;
}
Base64 data should be 4-bytes aligned. So for example the “z” that you’re returning should be Base64 encoded and padded like this: “eg==” to be Base64 compliant. You should do the same type of padding for the real hashed password.