Esempio n. 1
0
        public Account LogIn(DTO dto)
        {
            UserDTO userDTO = dto as UserDTO;

            if (userDTO != null)
            {
                string username = userDTO.getUsername();
                string password = userDTO.getPassword();

                User user = db.getUserByUsername(username);

                if (user != null)
                {
                    string salt     = user.Salt;
                    string passhash = Cryptographer.GetCrypt(password + HardSalt.Salt);
                    if (user.Passhash.Equals(passhash))
                    {
                        return(user.UserAccount);
                    }
                    else
                    {
                        throw new Exception("Invalid password!");
                    }
                }
                throw new Exception("Invalid username!");
            }
            return(null);
        }
Esempio n. 2
0
 /*
  * private string GetCrypt(string text)
  * {
  *  SHA512 alg = SHA512.Create();
  *  return Encoding.UTF8.GetString(alg.ComputeHash(Encoding.UTF8.GetBytes(text)));
  * }
  */
 public User(string username, string password, Account acc)
 {
     this.username = username;
     this.passhash = Cryptographer.GetCrypt(Cryptographer.GetCrypt(password + salt) + hardSalt);
     userAccount   = acc;
 }