public void TestMissingUserName() { //todo pass in a stub/mock ldap service so we can test ActiveDirectoryAuthentication authentication = new ActiveDirectoryAuthentication("janedoe", null); LoginRequest credentials = new LoginRequest(); bool isValid = authentication.Authenticate(credentials); Assert.IsFalse(isValid); }
public void TestValidUserName() { //todo pass in a stub/mock ldap service so we can test ActiveDirectoryAuthentication authentication = new ActiveDirectoryAuthentication(userName, null); authentication.DomainName = domainName; LoginRequest credentials = new LoginRequest(userName); bool isValid = authentication.Authenticate(credentials); Assert.IsTrue(isValid); }
public override Task <SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout) { if (ActiveDirectoryAuthentication.IsADAuthenticationEnabled()) { if (ActiveDirectoryAuthentication.Authenticate(userName, password)) { return(base.PasswordSignInAsync(userName, "bazooka", isPersistent, shouldLockout)); } } return(base.PasswordSignInAsync(userName, password, isPersistent, shouldLockout)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; if (db.Users.Count() == 0) { user.Administrator = true; } IdentityResult result; if (ActiveDirectoryAuthentication.IsADAuthenticationEnabled()) { if (!ActiveDirectoryAuthentication.Authenticate(model.UserName, model.Password)) { ModelState.AddModelError("", "username or password not valid"); return(View(model)); } else { result = await UserManager.CreateAsync(user, "bazooka"); } } else { result = await UserManager.CreateAsync(user, model.Password); } if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }