Appemdix A - StackOverflowException
Hello
I wrote the following code:
using System;
namespace Wrox.ProCSharp.OOProg
{
class MainEntryPoint
{
static void Main()
{
Authenticator myAccess = new Authenticator();
bool done;
done = myAccess.ChangePassword("", "MyNewPassword");
if (done == true)
Console.WriteLine("Password for myAccess changed");
else
Console.WriteLine("Failed to change password for myAccess");
done = myAccess.ChangePassword("", "AnotherPassword");
if (done == true)
Console.WriteLine("Password for myAccess changed");
else
Console.WriteLine("Failed to change password for myAccess");
if (myAccess.IsPasswordCorrect("WhatPassword"))
Console.WriteLine("Verified myAccess\' password");
else
Console.WriteLine("Failed to verify myAccess\' password");
uint minimo = Authenticator.minPasswordLength;
Console.WriteLine("Changed!");
}
}
public class Authenticator
{
// implementation as shown earlier
private string password = "";
//private static uint minPasswordLength = 6;
public static uint minPasswordLength
{
get
{
return minPasswordLength;
}
set
{
minPasswordLength = value;
}
}
/*public static uint GetMinPasswordLength()
{
return minPasswordLength;
}*/
public bool IsPasswordCorrect(string tryPassword)
{
return (tryPassword == password) ? true : false;
}
public bool ChangePassword(string oldPassword, string newPassword)
{
if (oldPassword == password)
{
password = newPassword;
return true;
}
else
return false;
}
}
}
But when I run the program, see the following error:
public static uint minPasswordLength
{
get
{
return minPasswordLength;
}
set
{
minPasswordLength = value;
}
}
"An unhandled exception of type 'System.StackOverflowException' occurred in ConsoleApplication7.exe"
How can I solve this problem?
|