Пример #1
0
 /// <summary>
 /// register for a new account
 /// </summary>
 /// <param name="userName">user name</param>
 /// <param name="passWd">password</param>
 /// <param name="msg">the return message</param>
 /// <returns>registeration is successful or not</returns>
 public bool Register(string userName, string passWd, out string msg)
 {                      
     // judge the existence of the username and password
     if (m_File.CheckUserExists(userName))
     {
         msg = "User Name has already existed!";
         Console.WriteLine(msg);
         return false;
     }
     if (m_File.CheckPasswordExists(passWd))
     {
         msg = "Password has already existed!";
         Console.WriteLine(msg);
         return false;
     }
     //verify the password is valid or not here
     VerifyPassword passwdVerifier = new VerifyPassword();
     if (!passwdVerifier.CheckPassword(passWd,out msg))
     {
        
         Console.WriteLine(msg);
         return false;
     }
     //add salt to the password
     TagAdder salt = new TagAdder(passWd);
     string harshedPasswd = salt.AddSalt();
     string tag = salt.GetTag();
     //save username and password to the file
     m_File.AddUser(userName, harshedPasswd, tag);
     msg = "Successfully Create a new account!";
     //Console.WriteLine(msg);
     return true;
 }
Пример #2
0
 /// <summary>
 /// Change the password of a user
 /// </summary>
 /// <param name="userName">user name </param>
 /// <param name="pwd"> new password </param>
 /// <param name="msg"> the ruturn message of this action </param>
 /// <returns>success or not</returns>
 public bool ChangePwd(string userName, string pwd, out string msg) 
 {
     //verify the password is valid or not here
     VerifyPassword passwdVerifier = new VerifyPassword();
     if (!passwdVerifier.CheckPassword(pwd, out msg))
     {
         Console.WriteLine(msg);
         return false;
     }
     //add salt to the password
     TagAdder salt = new TagAdder(pwd);
     string harshedPasswd = salt.AddSalt();
     string tag = salt.GetTag();
     //save username and password to the file
     m_File.ChangePwd(userName, pwd, tag);
     msg = "Successfully Change the Password!";
     //Console.WriteLine(msg);
     return true;
 }