Authenticator2.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:2k
- 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 = "";
- private static uint minPasswordLength = 6;
- 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;
- }
- }
- }