Esempio n. 1
0
        public async Task <UserCredential> CreateLogin(UserCredential userCredential)
        {
            if (userCredential.UserId <= 0)
            {
                throw new CallerException("UserId is required");
            }

            if (string.IsNullOrEmpty(userCredential.Password))
            {
                throw new CallerException("Password is required");
            }

            if (string.IsNullOrEmpty(userCredential.Username))
            {
                throw new CallerException("Username is required");
            }

            var userIdCredential = await UserCredentialLogic.GetUserCredential(userCredential.UserId);

            var usernameCredential = await UserCredentialLogic.GetUserCredential(userCredential.Username);

            if (userIdCredential != null || usernameCredential != null)
            {
                throw new CallerException("UserLogin already exists");
            }

            var passwordLogic = new PasswordLogic(Context);

            var passwordInvalid = passwordLogic.ValidatePasswordRegex(userCredential.Password);

            if (passwordInvalid)
            {
                throw new FriendlyException("ValidateCredential.PasswordRegexInvalid", "Proposed password does not meet requirements.");
            }

            userCredential.Password     = passwordLogic.HashAndSaltPassword(userCredential.Password, "", out string salt);
            userCredential.PasswordSalt = salt;

            var createdCredential = await UserCredentialLogic.Create(userCredential);

            createdCredential.Clean();

            return(createdCredential);
        }
Esempio n. 2
0
 protected T CreateTestControllerWith <T>(PasswordLogic password = null) where T : ApiController, new()
 {
     password = Eval <PasswordLogic>(Params.Password, password);
     return(new B2BUserController(password) as T);
 }
        public async Task Unlock(int userId)
        {
            var passwordLogic = new PasswordLogic(Context);

            await passwordLogic.ResetAttemptCount(userId);
        }