public bool IsValid(string account, string password, IProfileDao profile, IRsaToken rsaToken) { // 根據 account 取得自訂密碼 var passwordFromDao = profile.GetPassword(account); // 根據 account 取得 RSA token 目前的亂數 var randomCode = rsaToken.GetRandom(account); // 驗證傳入的 password 是否等於自訂密碼 + RSA token亂數 var validPassword = passwordFromDao + randomCode; var isValid = password == validPassword; return isValid; }
public bool IsValid(string account, string password, IProfileDao profile, IRsaToken rsaToken) { // 根據 account 取得自訂密碼 var passwordFromDao = profile.GetPassword(account); // 根據 account 取得 RSA token 目前的亂數 var randomCode = rsaToken.GetRandom(account); // 驗證傳入的 password 是否等於自訂密碼 + RSA token亂數 var validPassword = passwordFromDao + randomCode; var isValid = password == validPassword; return(isValid); }
public void IsValidTest() { //var stubProfile = new StubProfileDao(); IProfileDao stubProfile = Substitute.For <IProfileDao>(); stubProfile.GetPassword("joey").Returns("91"); //var stubToken = new StubTokenDao(); IRsaToken stubToken = Substitute.For <IRsaToken>(); stubToken.GetRandom("").ReturnsForAnyArgs("000000"); var target = new AuthenticationService(stubProfile, stubToken); var actual = target.IsValid("joey", "91000000"); Assert.IsTrue(actual); }