Esempio n. 1
0
 private bool IDmatched(string password)
 {
     using (var database = new DatabaseStuff())
     {
         string passHash  = database.Users.Single(i => i.UserName == UserName).Password;
         string givenPass = PasswordHandling.PasswordToHash(PasswordHandling.ConvertToSecureString(password), UserName);
         return(givenPass == passHash);
     }
 }
Esempio n. 2
0
        private void AskPassword(bool isNewUser)
        {
            Console.Clear();
            Console.Write("\n\n\tPassword:\t");
            string password = PasswordHandling.GetPassword();

            while (IsWrongPassword(password, isNewUser) && LoginTries < 3)
            {
                Console.Write("\n\n\tPassword:\t");
                password = PasswordHandling.GetPassword();
                LoginTries++;
            }
            if (LoginTries == 3 && IsWrongPassword(password, isNewUser))
            {
                throw new ArgumentException("\n\n\tToo many false attempts");
            }
            Password = PasswordHandling.PasswordToHash(PasswordHandling.ConvertToSecureString(password), UserName);
        }
Esempio n. 3
0
 public UserManager(string userName, string password, bool isNewUser = false)
 {
     LoginTries = 1;
     if (IsWrongUserName(userName, isNewUser))
     {
         AskUserName(isNewUser);
     }
     else
     {
         UserName = userName;
     }
     LoginTries = 1;
     if (IsWrongPassword(password, isNewUser))
     {
         AskPassword(isNewUser);
     }
     else
     {
         Password = PasswordHandling.PasswordToHash(PasswordHandling.ConvertToSecureString(password), UserName);
     }
     SetAccessibility(isNewUser);
     // If is new user create a user to database
     using (var database = new DatabaseStuff())
     {
         if (isNewUser)
         {
             try
             {
                 database.Users.Add(new User(UserName, Password, UserAccess));
                 database.SaveChanges();
             }
             catch (Exception e)
             {
                 Console.WriteLine(e.Message + " User could not get created");
             }
         }
         TheUser = database.Users.Single(u => u.UserName == UserName);
     }
 }