public ActionResult ForgetPasswordagency(string EmailId) { try { string RandomPassword = GenerateRandomPassword.GenerateRandomCode(10); if (!LoginData.CheckEmailIdExist(EmailId, RandomPassword)) { ViewBag.message = "If the entered email id exists then new password has been sent to the entered email id."; return(View()); } string imagepath = UrlExtensions.LinkToRegistrationProcess("Content/img/logo_email.png"); bool isResult = SendMail.Sendchangepassword(EmailId, RandomPassword, string.Empty, Server.MapPath("~/MailTemplate"), imagepath); if (isResult) { ViewBag.message = "If the entered email id exists then new password has been sent to the entered email id."; } else { ViewBag.message = "Error occurred. Please, try again later."; } return(View()); } catch (Exception Ex) { ViewBag.message = Ex.Message; return(View()); } }
public async Task <string> Handle(LoginUserExternalQuery request, CancellationToken cancellationToken) { var user = _mapper.Map <ApplicationUserDto>(_mediator.Send(new GetUserByEmailQuery(request.Email), cancellationToken).Result); if (user == null) { var newUser = new ApplicationUserDto() { Email = request.Email, UserName = request.Email, EmailConfirmed = true }; var result = await _mediator.Send(new CreateUserCommand(newUser, GenerateRandomPassword.SecurePassword()), cancellationToken); if (!result.Succeeded) { _logger.LogInformation($"LoginUserExternal: {request.Email}: Failed login: Failed to create a local user"); throw new InvalidRegisterException("Failed to register account with third party login provider"); } } else { if (user.AccountEnabled) { throw new AccountLockedException(); } } var claims = _mediator.Send(new GetUserClaimQuery(user), cancellationToken).Result; return(_mediator.Send(new GenerateLoginTokenQuery(claims), cancellationToken).Result);; }
public async Task <IHttpActionResult> NotRegisteredUserTask(TaskViewModel taskViewModel) { taskViewModel.Region = Denmark_addressess.GetMunicipalityCode(taskViewModel.ClientStreetName, taskViewModel.ClientPostCode.ToString(), taskViewModel.ClientHouseNumber, taskViewModel.ClientCity); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var randomPass = GenerateRandomPassword.GenerateRandomPass(); RegisterClient registerClient = new RegisterClient(); registerClient.Email = taskViewModel.ClientEmail; registerClient.Password = randomPass; registerClient.ConfirmPassword = randomPass; var user = new ApplicationUser() { UserName = taskViewModel.ClientEmail, Email = taskViewModel.ClientEmail }; IdentityResult result = await UserManager.CreateAsync(user, randomPass); if (result.Succeeded) { var UserId = UserManager.FindByEmail(taskViewModel.ClientEmail); ClientProvider.SaveClientInfo(taskViewModel.ClientName, taskViewModel.ClientEmail, UserId.Id); TaskProvider.SaveTaskRegisteredUser(taskViewModel, UserId.Id); UserManager.AddToRole(UserId.Id, "Client"); } if (!result.Succeeded) { return(GetErrorResult(result)); } var httpStatusCode = HttpStatusCode.Accepted; var responseMsg = new HttpResponseMessage(httpStatusCode) { Content = new StringContent("", Encoding.UTF8, "application/json") }; MitBudDBEntities mitBudDB = new MitBudDBEntities(); var UserEmail = mitBudDB.AspNetUsers.Where(x => x.Email == taskViewModel.ClientEmail).SingleOrDefault(); string token = await UserManager.GeneratePasswordResetTokenAsync(UserEmail.Id); Email.sendCreatePasswordByEmail(taskViewModel.ClientEmail, taskViewModel.ClientName, token); return(Ok()); }
public void Test_GenerateRandomPassword_RandomInputs() { var allowedSpecial = "[]()!@"; var randomBytes = new Byte[4]; var rngCrypto = new RNGCryptoServiceProvider(); rngCrypto.GetBytes(randomBytes); var randomGenerator = new Random(BitConverter.ToInt32(randomBytes, 0)); var capSize = GenerateRandomPassword.CapSize; for (int idx = 0; idx < 100000; idx++) { var minLength = randomGenerator.Next(10, capSize + 200 + 1); var maxLength = randomGenerator.Next(minLength - 100, minLength + 20 + 1); var requiredLC = randomGenerator.Next(0, capSize + 100 + 1); var requiredUC = randomGenerator.Next(0, capSize + 100 + 1); var requiredSpecial = randomGenerator.Next(0, capSize + 100 + 1); var requiredDigits = randomGenerator.Next(0, capSize + 100 + 1); var generateRandomPassword = new GenerateRandomPassword { MinLength = minLength, MaxLength = maxLength, RequiredLowerCaseLetters = requiredLC, RequiredUpperCaseLetters = requiredUC, RequiredSpecialChars = requiredSpecial, RequiredDigits = requiredDigits, AllowedSpecialChars = allowedSpecial }; var generatedPassword = string.Empty; try { var output = WorkflowInvoker.Invoke(generateRandomPassword); generatedPassword = Convert.ToString(output["Password"]); Assert.IsTrue(minLength <= generatedPassword.Length && generatedPassword.Length <= maxLength); Assert.IsTrue(generatedPassword.Count(Char.IsDigit) >= requiredDigits); Assert.IsTrue(generatedPassword.Count(Char.IsLower) >= requiredLC); Assert.IsTrue(generatedPassword.Count(Char.IsUpper) >= requiredUC); Assert.IsTrue(generatedPassword.Where(c => Char.IsLetterOrDigit(c) == false).All(allowedSpecial.Contains)); } catch (ArgumentException) { Assert.IsTrue(minLength > maxLength || minLength > GenerateRandomPassword.CapSize || maxLength > GenerateRandomPassword.CapSize || requiredLC > GenerateRandomPassword.CapSize || requiredUC > GenerateRandomPassword.CapSize || requiredSpecial > GenerateRandomPassword.CapSize || minLength < requiredLC + requiredUC + requiredDigits + requiredSpecial); } } }
public async Task <CreatedUserViewModel> CreateONGUser(string email) { var user = new ApplicationUser(email); var tempPassword = GenerateRandomPassword.Generate(8); var result = await _userManager.CreateAsync(user, tempPassword); if (!result.Succeeded) { throw new Exception(); } await _userManager.AddToRoleAsync(user, Roles.ONG); return(new CreatedUserViewModel { User = user, TempPassword = tempPassword }); }
public async Task <ActionResult> Create(CreateUserViewModel model) { if (ModelState.IsValid) { HttpPostedFileBase file = Request.Files[0]; if (file.ContentLength > 0) { var filename = Guid.NewGuid() + "-" + Path.GetFileName(file.FileName); if (System.Configuration.ConfigurationManager.AppSettings["StorageAccountName"] != null) { var azureUploadLocation = await StorageHelper.UploadFileToStorage(file.InputStream, filename); if (azureUploadLocation != null) { model.AppUser.PhotoUrl = azureUploadLocation; } } else { var path = Path.Combine(Server.MapPath("~/UploadedImages"), filename); file.SaveAs(path); model.AppUser.PhotoUrl = "/UploadedImages/" + filename; } } model.AppUser.UserName = model.Email; model.AppUser.Email = model.Email; model.AppUser.CreatedById = User.Identity.GetUserId(); model.AppUser.CreatedOn = DateTime.Now; var password = GenerateRandomPassword.Generate(12); var result = await base.UserManager.CreateAsync(model.AppUser, password); if (result.Succeeded) { UserManager.AddToRole(model.AppUser.Id, RoleName); string code = await UserManager.GenerateEmailConfirmationTokenAsync(model.AppUser.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = model.AppUser.Id, code = code }, protocol: Request.Url.Scheme); var message = String.Format(@"<html> <head> <meta charset='UTF-8'> <meta content='width=device-width, initial-scale=1' name='viewport'> <meta content='telephone=no' name='format-detection'> <title></title> </head> <body> <div class='es-wrapper-color'> <table class='es-wrapper' width='100%' cellspacing='0' cellpadding='0'> <tbody> <tr> <td class='esd-email-paddings' valign='top'> <table class='es-header' cellspacing='0' cellpadding='0' align='center'> <tbody> <tr> <td class='es-adaptive esd-stripe' align='center'> <table class='es-header-body' width='600' cellspacing='0' cellpadding='0' align='center'> <tbody> <tr> <td class='esd-structure es-p20t es-p20b es-p40r es-p40l' esd-general-paddings-checked='true' align='left'> <table width='100%' cellspacing='0' cellpadding='0'> <tbody> <tr> <td class='esd-container-frame' width='520' valign='top' align='center'> <table width='100%' cellspacing='0' cellpadding='0'> <tbody> <tr> <td class='esd-block-image es-m-p0l' align='center'> <img src='https://ojp8zqasz32qat8n13om56p4-wpengine.netdna-ssl.com/wp-content/uploads/2015/11/TheAmazingRaceLogo.png' width='250'> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <table class='es-content' cellspacing='0' cellpadding='0' align='center'> <tbody> <tr> <td class='esd-stripe' esd-custom-block-id='3109' align='center'> <table class='es-content-body' style='background-color: rgb(255, 255, 255);' width='600' cellspacing='0' cellpadding='0' bgcolor='#ffffff' align='center'> <tbody> <tr> <td class='esd-structure es-p20t es-p20b es-p40r es-p40l' esd-general-paddings-checked='true' align='left'> <table width='100%' cellspacing='0' cellpadding='0'> <tbody> <tr> <td class='esd-container-frame' width='520' valign='top' align='center'> <table width='100%' cellspacing='0' cellpadding='0'> <tbody> <tr> <td class='esd-block-text' align='left'> <h1 style='color: rgb(74, 126, 176);'>Welcome to The Race</h1> </td> </tr> <tr> <td class='esd-block-spacer es-p5t es-p20b' align='left'> <table width='5%' height='100%' cellspacing='0' cellpadding='0' border='0'> <tbody> <tr> <td style='border-bottom: 2px solid rgb(153, 153, 153); background: rgba(0, 0, 0, 0) none repeat scroll 0% 0%; height: 1px; width: 100%; margin: 0px;'></td> </tr> </tbody> </table> </td> </tr> <tr> <td class='esd-block-text es-p10b' align='left'> <br /> <p><span style='font-size: 16px; line-height: 150%;'>Hi {0},</span></p> <br /> </td> </tr> <tr> <td class='esd-block-text' align='left'> <p>You have been successfully registered to The Amazing Race. You can find your credential below:</p> <br /> </td> </tr> <tr> <td class='esd-block-text' align='left'> <p> <b>Role:</b> {1}<br /> <b>Email/Username:</b> {2}<br /> <b>Password:</b> {3}<br /> </td> </tr> <tr> <td class='esd-block-text' align='left'> <br /> <p> Best Regards,<br /> The Amazing Race Team </p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> <tr> <td class='esd-structure es-p20t es-p20b es-p40r es-p40l' esd-general-paddings-checked='true' align='left'> <table width='100%' cellspacing='0' cellpadding='0'> <tbody> <tr> <td class='esd-container-frame' width='520' valign='top' align='center'> <table width='100%' cellspacing='0' cellpadding='0'> <tbody> <tr> <td class='esd-block-spacer es-p20t es-p20b es-p5r' align='center'> <table width='100%' height='100%' cellspacing='0' cellpadding='0' border='0'> <tbody> <tr> <td style='border-bottom: 1px solid rgb(255, 255, 255); background: rgba(0, 0, 0, 0) none repeat scroll 0% 0%; height: 1px; width: 100%; margin: 0px;'></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> </body> </html>", model.AppUser.Name, RoleName, model.Email, password); await UserManager.SendEmailAsync(model.AppUser.Id, "Welcome to The Amazing Race Singapore", message); TempData["MessageAlert"] = new Alert { CssClass = "alert-success", Title = "Success!", Message = RoleName + " is successfully created." }; return(RedirectToAction("Create")); } AddErrors(result); } ViewData["GenderOptions"] = GenderOptions; return(View(model)); }