日期:2013-05-25 浏览次数:20386 次
using System;
namespace Wrox.ProCSharp.OOProg //The first program
{
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");
}
}
public class Authenticator
{
// implementation as shown earlier
private string password = "";
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;
}
}
}
using System;
namespace Wrox.ProCSharp.OOProg //The Second program
{
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 myA