Beispiel #1
0
    //private string _TestValidPassword = "******";
    //private string _TestSaltedHashedPassword = @"瞌訖ꎚ壿喐ຯ缟㕧";
    //private int _TestSalt = -54623530;
    //private string _TestInvalidUsername = "******";
    //private string _TestInvalidPassword = "******";

    /// <summary>
    /// Returns Success(true) if verify user is valid, Success(false) if invalid. Throws exceptions if something bad happens.
    /// </summary>
    /// <param name="username"></param>
    /// <param name="password"></param>
    /// <returns></returns>
    protected override bool? VerifyUserImpl(string username, string password)
    {
      bool? retResult = null;
      var results = from u in SeedData.Ton.Users
                    where u.Username == username
                    select u;

      if (results.Count() == 1)
      {
        //USERNAME FOUND. CHECK PASSWORD
        var userDto = results.First();
        SaltedHashedPassword saltedHashedPasswordObj =
          new SaltedHashedPassword(password, userDto.Salt);
        if (string.Compare(userDto.SaltedHashedPasswordValue,
                           saltedHashedPasswordObj.Value,
                           StringComparison.InvariantCulture) == 0)
        {
          //PASSWORDS MATCH
          retResult = true;
        }
        else
        {
          //PASSWORDS DO *NOT* MATCH
          retResult = false;
        }
      }
      else if (results.Count() == 0)
      {
        //USERNAME NOT FOUND.
        retResult = false;
      }
      else
      {
        //?? VERY BAD EXCEPTION. MULTIPLE USERS WITH THAT USERNAME FOUND?
        throw new Exceptions.VeryBadException();
      }

      return retResult;
    }
        /// <summary>
        /// Returns Success(true) if verify user is valid, Success(false) if invalid. Throws exceptions if something bad happens.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Result<bool?> VerifyUser(string username, string password)
        {
            //old
              //return Result<bool?>.Success(username == _TestValidUsername && password == _TestValidPassword);
              Result<bool?> retResult = Result<bool?>.Undefined(null);
              try
              {
            var results = from u in SeedData.Ton.Users
                      where u.Username == username
                      select u;

            if (results.Count() == 1)
            {
              //USERNAME FOUND. CHECK PASSWORD
              var userDto = results.First();
              SaltedHashedPassword saltedHashedPasswordObj =
            new SaltedHashedPassword(password, userDto.Salt);
              if (string.Compare(userDto.SaltedHashedPasswordValue,
                             saltedHashedPasswordObj.Value,
                             StringComparison.InvariantCulture) == 0)
              {
            //PASSWORDS MATCH
            retResult = Result<bool?>.Success(true);
              }
              else
              {
            //PASSWORDS DO *NOT* MATCH
            retResult = Result<bool?>.Success(false);
              }
            }
            else if (results.Count() == 0)
            {
              //USERNAME NOT FOUND.
              retResult = Result<bool?>.Success(false);
            }
            else
            {
              //?? VERY BAD EXCEPTION. MULTIPLE USERS WITH THAT USERNAME FOUND?
              throw new Exceptions.VeryBadException();
            }

              }
              catch (Exception ex)
              {
            retResult = Result<bool?>.FailureWithInfo(null, ex);
              }

              return retResult;
        }