public Holder <User> SignUp(User user) { User userFromDb = _userDatabase.GetUserByPassportId(user.PassportId); if (userFromDb != null) { return(CheckUser(user, 400, "User with this passport is already registered")); } List <User> usersFromDb = new List <User>(); usersFromDb = _userDatabase.GetUsers(); foreach (var userDb in usersFromDb) { if (String.Compare(userDb.Email, user.Email) == 0) { return(CheckUser(user, 400, "User with this email already exists")); } } string[] encryptedUserPassword = PasswordHelper.EncryptPassword(user.Key); string safePassword = PasswordHelper.GetMeAString(encryptedUserPassword[1]); string salt = PasswordHelper.GetMeAString(encryptedUserPassword[0]); user.Key = safePassword; user.Salt = salt; return(_userDatabase.SignUp(user) ? CheckUser(user, 200, "") : CheckUser(user, 400, "Unable to register user")); }