Authenticator.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:1k
- 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");
- }
- }
- 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;
- }
- }
- }