Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public virtual bool ResetPassword(string userName, string password)
        {
            var ret       = false;
            var resetUser = UserHelper.RetrieveResetUserByUserName(userName);

            if (resetUser == null)
            {
                return(ret);
            }

            string sql         = "set Password = @0, PassSalt = @1 where UserName = @2";
            var    passSalt    = LgbCryptography.GenerateSalt();
            var    newPassword = LgbCryptography.ComputeHash(password, passSalt);
            var    db          = DbManager.Create();

            try
            {
                db.BeginTransaction();
                ret = db.Update <User>(sql, newPassword, passSalt, userName) == 1;
                if (ret)
                {
                    db.Execute("delete from ResetUsers where UserName = @0", userName);
                }
                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(ret);
        }
Exemplo n.º 2
0
        public void ResetReasonsByUserName_Ok()
        {
            var user = new User {
                UserName = "******", Password = "******", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg"
            };

            Assert.True(UserHelper.Save(user));

            UserHelper.ForgotPassword(new ResetUser()
            {
                UserName = user.UserName, DisplayName = user.DisplayName, Reason = "UnitTest", ResetTime = DateTime.Now
            });
            Assert.NotNull(UserHelper.RetrieveResetUserByUserName(user.UserName));

            var reasons = UserHelper.RetrieveResetReasonsByUserName(user.UserName);

            Assert.NotEmpty(reasons);

            UserHelper.Delete(new string[] { user.Id });
        }