public void ValidatePassword_WrongPassword_ShouldReturnFalse() { var user = PasswordHashService.HashPassword("Pa55word"); bool result = PasswordHashService.ValidatePassword("Password", user); Assert.IsFalse(result); }
public ActionResult Login(LoginUserViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var query = from u in db.Users where u.Name == model.Username select u; var user = query.FirstOrDefault(); if (user == null || !PasswordHashService.ValidatePassword(model.Password, user.Password)) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Autoryzacja użytkownika nie przebiegła pomyślnie."); return(View(model)); } UserSessionContext us = new UserSessionContext(HttpContext); us.SetUserId(user.Id); return(RedirectToAction("Index", "Character")); }
public void ValidatePassword_CorrectPassword_ShouldReturnTrue() { var user = PasswordHashService.HashPassword("Pa55word"); bool result = PasswordHashService.ValidatePassword("Pa55word", user); Assert.IsTrue(result); }
public ActionResult Register(RegisterUserViewModel model) { var query = from u in db.Users where u.Name == model.Username select u; if (query.Any()) { ModelState.AddModelError("Username", "Podany użytkownik już istnieje."); } if (!ModelState.IsValid) { return(View(model)); } User user = new User() { Role = UserRole.Normal, Name = model.Username, Password = PasswordHashService.CreateHash(model.Password) }; try { db.Users.Add(user); db.SaveChanges(); } catch (Exception) { return(View(model)); } return(RedirectToAction("Login")); }
public RegisterViewModel(IUnityContainer container, IEventAggregator eventAggregator, ILoggerFacade logger, IRegionManager regionManager, AuthenticationService authenticationService, AddressStorage addressStorage, PasswordHashService passwordHashService) { if (container == null || eventAggregator == null || logger == null || regionManager == null || authenticationService == null || addressStorage == null || passwordHashService == null) { throw new ArgumentException(); } this._container = container; this._eventAggregator = eventAggregator; this._logger = logger; this._regionManager = regionManager; this._authenticationService = authenticationService; this._addressStorage = addressStorage; this._passwordHashService = passwordHashService; // Trigger the getter once in order to force the view to load // any existing selected addresses. SelectedServerAddress = this._addressStorage.ServerAddress; // Ensure that the visible servers are updated. this._eventAggregator.GetEvent <ServerAddedEvent>() .Subscribe(() => { RaisePropertyChanged(nameof(ServerAddresses)); }, ThreadOption.UIThread); // Ensure that existing information are removed when logging in. this._eventAggregator.GetEvent <LoginEvent>() .Subscribe(this.RemoveLoginInformation, ThreadOption.UIThread, false, (b) => { return(b); }); ButtonRegister = new DelegateCommand(async() => { await this.ButtonRegisterClicked(); }); PasswordChangedCommand = new DelegateCommand <PasswordBox>(async(box) => { await this.PasswordChangedFired(box); }); }
/// <summary> /// Creates Register Controller /// </summary> /// <param name="dataManager">Data manager</param> /// <param name="verifier">Verifier</param> /// <param name="passwordHashService">Password Hash Sevice</param> public RegisterController(DataManager dataManager, Verifier verifier, PasswordHashService passwordHashService) { // setting fields this._dataManager = dataManager; this._verifier = verifier; this._passwordHS = passwordHashService; }
public ActionResult Register(RegisterDto registerDto) { if (!ModelState.IsValid) { return(View(registerDto)); } if (registerDto.RepeatedPassword != registerDto.Password) { ModelState.AddModelError(nameof(registerDto.Password), "Пароли не совпадают"); ModelState.AddModelError(nameof(registerDto.RepeatedPassword), "Пароли не совпадают"); return(View(registerDto)); } var existedUser = UserDataStore.GetAll() .SingleOrDefault(user => user.Login == registerDto.Login && user.PasswordHash == string.Empty); if (existedUser == null) { ModelState.AddModelError(nameof(registerDto.Login), "Данный логин недоступен, обратитесь к администратору"); return(View(registerDto)); } existedUser.PasswordHash = PasswordHashService.GetHash(registerDto.Password); UserDataStore.Update(existedUser); return(RedirectToAction("Index")); }
public SeedData(MembershipContext _db, PasswordHashService _p_hasher, UserManager <ApplicationUser> _userManager, RoleManager <ApplicationRole> _roleManager) { db = _db; p_hasher = _p_hasher; roleManager = _roleManager; userManager = _userManager; }
static void Main(string[] args) { var hasher = new PasswordHashService(); Console.Write("Password : "******"Password Hash: {passwordHash}"); Console.ReadLine(); }
public async static void Initialize(MembershipContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager) //UserManager<ApplicationUser> userManager) { // Do any initialization code here for the DB. // Can include populate lookups, data based configurations etc. //SeedData seed_data; PasswordHashService p_hasher = new PasswordHashService(); SeedData seed_data = new SeedData(context, p_hasher, userManager, roleManager); //, roleManager, userManager); // Get counts if users. Task <int> numUsersResult = SumUsers(context); int numUsers = await SumUsers(context); // Get counts of data. Do this asynchronously. Task <int> numMembersResult = SumMembers(context); int numMembers = await SumMembers(context); Task <int> numMemberDetailsResult = SumMemberDetails(context); int numMemberDetails = await SumMemberDetails(context); Task <int> numMemberAddressResult = SumMemberAddresses(context); int numMemberAddresses = await SumMemberAddresses(context); // Full rebuild user authentication data - If no User data then regenerate User/Role records. if (numUsers == 0) { // Create initial users and roles. //seed_data.CreateUsersAsync(); seed_data.CreateUsers(); } // Full rebuild data - If no Member data then regenerate Member base table and all child tables. if (numMembers == 0) { // Add 50 random members to database. seed_data.GenerateMembers(50); } // If Member base table exists and child tables don't then generate those. if ((numMembers > 0) && (numMemberDetails == 0)) { seed_data.GenerateMemberDetails(); } // If Member base table exists and child tables don't then generate those. if ((numMembers > 0) && (numMemberAddresses == 0)) { seed_data.GenerateMemberAddresses(); } }
public User Login(LoginPassDto loginPasswordDto) { var passHash = PasswordHashService.GetHash(loginPasswordDto.Password); var user = UserDataStore.GetAll() .SingleOrDefault(u => u.Login == loginPasswordDto.Login && u.PasswordHash == passHash); if (user != null) { CreateCookie(user, loginPasswordDto.RememberMe); } return(user); }
protected override void Seed(DatabaseContext context) { var users = new List <User> { new User { Name = "admin", Password = PasswordHashService.CreateHash("admin"), Role = UserRole.Admin }, new User { Name = "*****@*****.**", Password = PasswordHashService.CreateHash("user"), Role = UserRole.Normal } }; users.ForEach(o => context.Users.Add(o)); context.SaveChanges(); }
public void HashPassword_CorrectData_ShouldReturnHashedPassword() { string password = "******"; string hashedPass = String.Empty; string salt = String.Empty; for (int i = 0; i < 50; i++) { var user = PasswordHashService.HashPassword(password); var newHashedPass = user.PasswordHash; var newSalt = user.Salt; Assert.That(hashedPass, Is.Not.EqualTo(newHashedPass)); Assert.That(salt, Is.Not.EqualTo(newSalt)); hashedPass = newHashedPass; salt = newSalt; } }
public AccountService ( IMapper mapper, UserService userService, IUserRepository userRepository, IJwtHandler jwtHandler, IPasswordHasher <SignInViewModel> passwordHasher, PasswordHashService passwordHashService, NotificationService notificationService ) { _mapper = mapper; _userService = userService; _userRepository = userRepository; _jwtHandler = jwtHandler; _passwordHasher = passwordHasher; _passwordHashService = passwordHashService; _notificationService = notificationService; }
public override async Task UpdateAsync(UserModel model) { var command = new UpdateUserCommand(model.Id) { Entity = _mapper.Map <User>(model) }; if (!command.IsValid()) { await RaiseValidationErrorsAsync(command); return; } var dbEntity = await _userRepository.GetByIdAsync(command.Entity.Id); if (dbEntity == null) { await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType, CoreUserMessages.RegistroNaoEncontrado.Message)); return; } var listaUser = await _userRepository.GetAllAsync(); if (listaUser.Any(c => c.Id != command.Entity.Id && string.Equals(c.Username, command.Entity.Username, StringComparison.CurrentCultureIgnoreCase))) { await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType, CoreUserMessages.ValorDuplicadoO.Format("Username").Message)); return; } command.Entity.Password = PasswordHashService.Hash(command.Entity.Password); _mapper.Map(command.Entity, dbEntity); command.Entity = dbEntity; await _mediatorHandler.SendCommandAsync(command); }
public async Task <IActionResult> Register([FromBody] RegisterRequest request) { string hashedPassword = PasswordHashService.HashPassword(request.Password); var user = new User { Email = request.Email, UserName = request.UserName, Password = hashedPassword }; User registeredUser = await _userService.RegisterAsync(user); if (registeredUser != null) { ClaimsPrincipal claimsPrincipal = _userService.CreateClaimsPrinciple(user); await Request.HttpContext.SignInAsync("Cookies", claimsPrincipal); return(Ok(new { test = "test" })); } return(BadRequest()); }
static void Main(string[] args) { //var uof = new UnitOfWork(new ApplicationContext()); //using (var container = ConfigurerBLL.ConfigureDependencies()) //{ // var uof = container.Resolve<IUnitOfWork>(); // var userService = container.Resolve<IUserService>(); // var postService = container.Resolve<IPostService>(); // //postService.SetLike(new LikeDTO {PostId = 3, UserId = 1}); // //userService.CreateUser(new UserDTO() // //{ // // Name = "Maks", // // Password = "******", // // Surname = "Maks", // // Role = "Admin", // // Rating = 0, // // Email= "*****@*****.**", // //}); // //var user = userService.GetUserById(1); // //Console.WriteLine($"{user.Email} {user.Password} {user.GetType()}"); // //var x = userService.GetUserByEmailAndPass(user.Email, user.Password); // //Console.WriteLine(x.GetType()); // //foreach (var userDto in userService.GetAll()) // //{ // // Console.WriteLine($"{userDto.Name} {userDto.Password} {userDto.GetType()}"); // //} //} Console.WriteLine(PasswordHashService.Hash("Admin_123")); Console.WriteLine(PasswordHashService.Hash("Admin_123")); var x = PasswordHashService.Hash("Admin_123"); Console.WriteLine(PasswordHashService.Check(PasswordHashService.Hash("Admin_123"), "Admin_123")); Console.WriteLine(PasswordHashService.Check(PasswordHashService.Hash("Admin_123"), "Admin_12")); }
public RegistrationService() { _sessionRepo = new SessionInstanceRepository(); _connRepo = new ConnectionRepository(); _passwordService = new PasswordHashService(); }
public AccountController(UserService userService, PasswordHashService passwordHashService) { _userService = userService; _passwordHashService = passwordHashService; }
public SignUpController() { this._hasher = Globals.Hasher; this._mailer = Globals.Mailer; }
public PasswordHashServiceTests() { _service = new PasswordHashService(); }
public User GetByCredentials(string username, string inputPassword) { return(Query().Where(u => u.Username == username) .AsEnumerable() .Where(u => PasswordHashService.Verify(inputPassword, u.Password)).FirstOrDefault()); }
public BaseController() { unit = new UnitOfWork(); service = new PasswordHashService(); }
public AccountsApplicationService(IAccountsRepository accounts, PasswordHashService hasher) { _accounts = accounts; _hasher = hasher; }
/// <summary> /// Creates new instance of user controller /// </summary> public UsersController(DataManager dataManager, PasswordHashService passwordHashService) { this._dataManager = dataManager; this._passwordHashService = passwordHashService; }
public LoginCallNativeModel(CosmosDbService DbService, PasswordHashService PasswordHashService) { _dbService = DbService; _passwordService = PasswordHashService; }