public void Hash_Password_Success()
        {
            string password     = "******";
            string expectedHash = "7bcf9d89298f1bfae16fa02ed6b61908fd2fa8de45dd8e2153a3c47300765328";

            string actualHash = hashing.ComputeSha256Hash(password);


            Assert.AreEqual(expectedHash, actualHash);
        }
Example #2
0
 public Account(string userName, string password, string firstname, string lastname)
 {
     Username  = userName;
     Firstname = firstname;
     Lastname  = lastname;
     if (!string.IsNullOrWhiteSpace(password))
     {
         Salt = Salting.RandomString(new Random().Next(10, 25));
     }
     PasswordHash = Hashing.ComputeSha256Hash(string.Concat(Salt, password));
 }
Example #3
0
        public Account AuthenticateUser()
        {
            Account account = new Account();

            try
            {
                if (string.IsNullOrEmpty(Username) || string.IsNullOrWhiteSpace(Username))
                {
                    return(account = null);
                }

                if (AccountDataService.DoesPlayerExistWithName(context, Username.ToLower()))
                {
                    account = AccountDataService.GetAccountByName(context, Username.ToLower());

                    string saltedPassword = string.Concat(account.Salt, Password);
                    string hashedPassword = Hashing.ComputeSha256Hash(saltedPassword);

                    bool matchedPassword = string.Equals(account.PasswordHash, hashedPassword);

                    if (matchedPassword)
                    {
                        account.PasswordHash = hashedPassword;
                        Globals.LoggedInUser = account;
                        return(account);
                    }
                    else
                    {
                        return(account = null);
                    }
                }
                return(account = null);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #4
0
 public ActionResult <LoginResponse> Get([FromQuery] LoginRequest loginRequest)
 {
     if (_dataStore.Select <UserInfo>(CollectionMeta.UserCollection).Any(x => x.Email == loginRequest.Username))
     {
         Random randomNumberGenerator = new Random();
         var    otp  = randomNumberGenerator.Next(1000, 9999);
         var    hash = Hashing.ComputeSha256Hash(otp.ToString());
         //var tempOTPPath = System.IO.Path.GetTempPath() + "\\OTP.txt";
         //System.IO.File.AppendAllText(tempOTPPath, Environment.NewLine + DateTime.Now.ToString() + "\t" + otp + "\t" + hash + "\t" + loginRequest.Username);
         //EmailHelper.SendEmail("C.A.T OTP", "Your OTP: " + otp.ToString(), loginRequest.Username);
         var result = new LoginResponse
         {
             Otp        = hash,
             StatusCode = 200,
             Status     = "OTP Generated Successfully"
         };
         return(Ok(result));
     }
     else
     {
         return(NotFound());
     }
 }