public void Validate_LongString_ReturnFalse(string input, int min, int max) { // regardless of validation criteria passed, too long must fail Assert.False(ValidationUtils.IsMatch(ValidationCriterion.AlphanumericOnly, input, min, max)); Assert.False(ValidationUtils.IsMatch(ValidationCriterion.AlphabeticOnly, input, min, max)); Assert.False(ValidationUtils.IsMatch(ValidationCriterion.SpecialCharacter, input, min, max)); Assert.False(ValidationUtils.IsMatch(validationCriteriaContradictorySpecialCharButAlphaNumOnly, input, min, max)); }
public async Task <IActionResult> OpenAccount([FromHeader] string Authorization, [FromHeader] string accountNickname, [FromHeader] string type) { try { //TODO middleware/filter would be better if (TokenUtils.IsValidFormatTokenString(Authorization) && TokenUtils.ValidateToken(Authorization, out SecurityToken token) && !_tokenService.IsTokenBlackListed(token)) { int id = TokenUtils.GetUserIDFromToken(Authorization, token); Models.User user = _userService.GetById(id); if (user != null && ValidationUtils.IsMatch(Settings.AccountNameCriterion, accountNickname, Settings.AccountNameMinLength, Settings.AccountNameMaxLength)) { AccountType accountType = (AccountType)Enum.Parse(typeof(AccountType), type, true); AccountHolder primaryAccountHolder = new AccountHolder() { AccountHolderType = AccountHolderType.Primary, Holder = user }; Account account = _accountService.OpenAccount(primaryAccountHolder, accountType, accountNickname); // TODO move this to account service instead _context.AccountHolders.Add(primaryAccountHolder); _context.Accounts.Add(account); _context.SaveChanges(); return(Ok(String.Format("New {0} account created with nickname {1}", accountType.ToString(), accountNickname))); } return(BadRequest("Cannot create account using account type and nickname supplied.")); } else { return(BadRequest("Unable to authorize account creation. Check credentials and try again.")); } } catch (Exception ex) { // TODO put more informative exception message to log System.Console.WriteLine(ex.Message); return(BadRequest("A problem occurred. A new account was not created.")); } }
public IActionResult Register([FromHeader] string username, [FromHeader] string password, [FromBody] JObject userData) { var user = userData.ToObject <User>(); // TODO add checks to password lengths and complexity if (String.IsNullOrWhiteSpace(username) || password.Equals(HashUtils.EmptyStringHash) || String.IsNullOrWhiteSpace(user.FName) || String.IsNullOrWhiteSpace(user.LName)) { return(BadRequest("Invalid params for user registration.")); } if (!ValidationUtils.IsMatch(Settings.UsernameCriterion, username, Settings.UsernameMinLength, Settings.UsernameMaxLength)) { return(BadRequest(String.Format("Illegal characters in username. Usernames must have {0}.", Settings.UsernameValidationMessage))); } var users = _context.Users.Where(u => u.Username == username); if (users.Count() == 0) { Tuple <byte[], string> hashAndSalt = HashUtils.HashWithNewSalt(password); var testUser = new Models.User { Username = username, FName = user.FName, LName = user.LName, Password = hashAndSalt.Item1, Salt = hashAndSalt.Item2 }; _context.Users.Add(testUser); _context.SaveChanges(); return(Ok(String.Format("New user {0} created", username))); } return(BadRequest("Username already exists.")); }
public void Validate_AlphabeticValid_ReturnTrue(string input, int min, int max) { Assert.True(ValidationUtils.IsMatch(ValidationCriterion.AlphanumericOnly, input, min, max)); }
public void Validate_ContradictoryValidationCriteria_ReturnFalse(string input, int min, int max) { Assert.False(ValidationUtils.IsMatch(validationCriteriaContradictorySpecialCharButAlphaNumOnly, input, min, max)); }
public void Validate_SpecialCharsValid_ReturnTrue(string input, int min, int max) { Assert.True(ValidationUtils.IsMatch(ValidationCriterion.SpecialCharacter, input, min, max)); }