예제 #1
0
        public Domain.Enum.UserLoginResult ValidateUser(string usernameOrEmail, string password)
        {
            var user = GetUserByUserNameOrEmail(usernameOrEmail);

            if (user == null)
            {
                return(UserLoginResult.UserNotExist);
            }
            if (user.IsLocked)
            {
                return(UserLoginResult.Locked);
            }
            if (!user.IsActivated)
            {
                return(UserLoginResult.NotActive);
            }

            var passwordHash = Cipher.Hash(password, user.PasswordSalt);
            var isValid      = passwordHash.Equals(user.Password);

            if (!isValid)
            {
                return(UserLoginResult.WrongPassword);
            }

            //save last login date
            user.LastLoginDate = DateTime.Now;
            user.LastActiveIP  = XRequest.GetIP();
            user.TryCount      = 0;
            UserService.SubmitChanges();
            return(UserLoginResult.Successful);
        }
예제 #2
0
        public void InsertUser(User user)
        {
            var passwordSalt = Cipher.GenerateSalt();
            var passwordHash = Cipher.Hash(user.Password, passwordSalt);

            user.PasswordSalt = passwordSalt;
            user.Password     = passwordHash;
            user.BindAccount  = user.BindAccount ?? string.Empty;

            //setting default value:
            user.RoleID        = EnumUserRole.NormalUser.ToInt();
            user.Grade         = 1;
            user.EntryDate     = DateTime.Now;
            user.LastLoginDate = DateTime.Now;
            user.IsActivated   = true;
            user.IsLocked      = false;
            user.IsAutoAdded   = false;
            user.LoginTimes    = 1;
            user.LastActiveIP  = XRequest.GetIP();
            user.GUID          = Guid.NewGuid();
            UserService.Insert(user);
            UserService.SubmitChanges();
        }