Example #1
0
        protected override bool?VerifyUserImpl(string username, string password)
        {
            using (var ctx = LearnLanguagesContextManager.Instance.GetManager())
            {
                var results = from userData in ctx.ObjectContext.UserDatas
                              where userData.Username == username
                              select userData;

                if (results.Count() == 1)
                {
                    var user          = results.First();
                    var authenticated = (SaltedHashedPassword.GetHashedPasswordValue(password, user.Salt) == user.SaltedHashedPasswordValue);

                    //RETURNS SUCCESS IF VALIDATION IS AUTHENTICATED OR NOT.  DOES *NOT* THROW EXCEPTION
                    //IF CREDENTIALS ARE INVALID.
                    return(authenticated);
                }
                else
                {
                    if (results.Count() == 0)
                    {
                        return(false); //FALSE BECAUSE USER NOT FOUND
                    }
                    else
                    {
                        //results.count is not one or zero.  either it's negative, which would be framework absurd, or its more than one,
                        //which means that we have multiple users with the same username.  this is very bad.
                        var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException,
                                                     DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero);
                        throw new Exceptions.VeryBadException(errorMsg);
                    }
                }
            }
        }