Password authentication

R

Roy Gourgi

HI,

Why is this password authentication not working as I am sending? I am trying
to change the password and yet it is not working. What am I doing wrong?

TIA

Roy





using System;

public class Authenticator

{

private string Password;

public bool IsPasswordCorrect(string password)

{

return (password == Password) ? true : false;

}

public bool ChangePassword(string oldPassword, string newPassword)

{

if (oldPassword == Password)

{

Password = newPassword;

Console.WriteLine("Inside EQUAL {0} ",Password);

Console.ReadLine();

return true;

}

else

{

Console.WriteLine("Inside NOT EQUAL {0} ",Password);

Console.ReadLine();

return false;

}


}

}



class clsMain

{

static void Main()

{

Authenticator Simon = new Authenticator();

bool Done;

Done= Simon.ChangePassword("", "MyNewPassword");

if (Done==true)

Console.WriteLine("password for Simon changed");

else

Console.WriteLine("Failed to change password for Simon");


if (Simon.IsPasswordCorrect("what pw"))

Console.WriteLine("Verified ");

else

Console.WriteLine("NOT Verified ");

Console.ReadLine();

}

}
 
R

Roy Gourgi

Hi,
Yes that is right it is returning false. So how would I do it. I took this
example straight out of a book. So much for that. :)

Roy
 
S

SP

Roy Gourgi said:
HI,

Why is this password authentication not working as I am sending? I am
trying to change the password and yet it is not working. What am I doing
wrong?

private string Password;
public bool ChangePassword(string oldPassword, string newPassword)
{
if (oldPassword == Password)
{

Authenticator Simon = new Authenticator();

bool Done;

Done= Simon.ChangePassword("", "MyNewPassword");

I assume Done is returning false. That is because you are comparing an empty
length string to a null string, which will return false;

SP
 
S

SP

Roy Gourgi said:
Hi,
Yes that is right it is returning false. So how would I do it. I took this
example straight out of a book. So much for that. :)

Roy

you can declare Password as private string Password = "";

SP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top