public virtual async Task <ActionResult> ResetPassword(ResetPasswordViewModel model) { Guid guid; Guid guid1; this.CheckModelState(); IActiveUnitOfWork current = this._unitOfWorkManager.Current; current.DisableFilter(new string[] { "MayHaveTenant" }); long num = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId, "gsKnGZ041HLL4IM8")); FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(num); if (userByIdAsync == null || userByIdAsync.PasswordResetCode.IsNullOrEmpty() || userByIdAsync.PasswordResetCode != model.ResetCode) { throw new UserFriendlyException(this.L("InvalidPasswordResetCode"), this.L("InvalidPasswordResetCode_Detail")); } TenantLogosEditDto tenantLogosEditDto = Abp.Threading.AsyncHelper.RunSync <TenantLogosEditDto>(() => this.GetCurrentTenantLogos()); dynamic viewBag = this.ViewBag; guid = (tenantLogosEditDto.HeaderImageId.HasValue ? tenantLogosEditDto.HeaderImageId.Value : Guid.Empty); viewBag.TenantCompanyHeaderImageId = guid; dynamic obj = this.ViewBag; guid1 = (tenantLogosEditDto.HeaderMobileImageId.HasValue ? tenantLogosEditDto.HeaderMobileImageId.Value : Guid.Empty); obj.TenantCompanyHeaderMobileImageId = guid1; return(this.View(model)); }
public virtual async Task <ActionResult> EmailConfirmation(EmailConfirmationViewModel model) { CheckModelState(); _unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant); var userId = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId)); var user = await _userManager.GetUserByIdAsync(userId); if (user == null || user.EmailConfirmationCode.IsNullOrEmpty() || user.EmailConfirmationCode != model.ConfirmationCode) { throw new UserFriendlyException(L("InvalidEmailConfirmationCode"), L("InvalidEmailConfirmationCode_Detail")); } user.IsEmailConfirmed = true; user.EmailConfirmationCode = null; await _userManager.UpdateAsync(user); var tenancyName = user.TenantId.HasValue ? (await _tenantManager.GetByIdAsync(user.TenantId.Value)).TenancyName : ""; return(RedirectToAction( "Login", new { successMessage = L("YourEmailIsConfirmedMessage"), tenancyName = tenancyName, userNameOrEmailAddress = user.UserName })); }
public virtual async Task <ActionResult> ResetPassword(ResetPasswordFormViewModel model) { this.CheckModelState(); IActiveUnitOfWork current = this._unitOfWorkManager.Current; current.DisableFilter(new string[] { "MayHaveTenant" }); long num = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId, "gsKnGZ041HLL4IM8")); FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(num); if (userByIdAsync == null || userByIdAsync.PasswordResetCode.IsNullOrEmpty() || userByIdAsync.PasswordResetCode != model.ResetCode) { throw new UserFriendlyException(this.L("InvalidPasswordResetCode"), this.L("InvalidPasswordResetCode_Detail")); } userByIdAsync.Password = (new PasswordHasher()).HashPassword(model.Password); userByIdAsync.PasswordResetCode = null; userByIdAsync.IsEmailConfirmed = true; userByIdAsync.ShouldChangePasswordOnNextLogin = false; await this._userManager.UpdateAsync(userByIdAsync); if (userByIdAsync.IsActive) { await this.SignInAsync(userByIdAsync, null, false); } return(this.RedirectToAction("Index", "Application")); }
public string ExtractTokenIfValid(string token) { try { string decryptedToken = null; try { decryptedToken = _cryptoService.Decrypt(token); } catch { var urlDecoded = HttpUtility.UrlDecode(token); decryptedToken = _cryptoService.Decrypt(urlDecoded); } var resetToken = new SimpleStringCipher().Decrypt(decryptedToken); var data = resetToken.Split('|'); var utcTicks = long.Parse(data[2]); if (DateTime.UtcNow - new DateTime(utcTicks) > TimeSpan.FromHours(1)) { return(null); } return(decryptedToken); } catch (Exception e) { return(null); } }
public virtual async Task <ActionResult> ResetPassword(ResetPasswordFormViewModel model) { CheckModelState(); _unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant); var userId = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId)); var user = await _userManager.GetUserByIdAsync(userId); if (user == null || user.PasswordResetCode.IsNullOrEmpty() || user.PasswordResetCode != model.ResetCode) { throw new UserFriendlyException(L("InvalidPasswordResetCode"), L("InvalidPasswordResetCode_Detail")); } user.Password = new PasswordHasher().HashPassword(model.Password); user.PasswordResetCode = null; user.IsEmailConfirmed = true; user.ShouldChangePasswordOnNextLogin = false; await _userManager.UpdateAsync(user); if (user.IsActive) { await SignInAsync(user); } return(RedirectToAction("Index", "Application")); }
public virtual async Task <JsonResult> Login(LoginViewModel loginModel, string returnUrl = "") { CheckModelState(); _unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant); var loginResult = await GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, loginModel.TenancyName); if (loginResult.User.ShouldChangePasswordOnNextLogin) { loginResult.User.SetNewPasswordResetCode(); return(Json(new MvcAjaxResponse { TargetUrl = Url.Action( "ResetPassword", new ResetPasswordViewModel { UserId = SimpleStringCipher.Encrypt(loginResult.User.Id.ToString()), ResetCode = loginResult.User.PasswordResetCode }) })); } await SignInAsync(loginResult.User, loginResult.Identity, loginModel.RememberMe); if (string.IsNullOrWhiteSpace(returnUrl)) { returnUrl = Url.Action("Index", "Application"); } return(Json(new MvcAjaxResponse { TargetUrl = returnUrl })); }
public virtual async Task <ActionResult> EmailConfirmation(EmailConfirmationViewModel model) { string tenancyName; this.CheckModelState(); IActiveUnitOfWork current = this._unitOfWorkManager.Current; current.DisableFilter(new string[] { "MayHaveTenant" }); long num = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId, "gsKnGZ041HLL4IM8")); FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(num); if (userByIdAsync == null || userByIdAsync.EmailConfirmationCode.IsNullOrEmpty() || userByIdAsync.EmailConfirmationCode != model.ConfirmationCode) { throw new UserFriendlyException(this.L("InvalidEmailConfirmationCode"), this.L("InvalidEmailConfirmationCode_Detail")); } userByIdAsync.IsEmailConfirmed = true; userByIdAsync.EmailConfirmationCode = null; await this._userManager.UpdateAsync(userByIdAsync); if (!userByIdAsync.TenantId.HasValue) { tenancyName = ""; } else { TenantManager tenantManager = this._tenantManager; int? tenantId = userByIdAsync.TenantId; tenancyName = (await tenantManager.GetByIdAsync(tenantId.Value)).TenancyName; } string str = tenancyName; ActionResult action = this.RedirectToAction("Login", new { successMessage = this.L("YourEmailIsConfirmedMessage"), tenancyName = str, userNameOrEmailAddress = userByIdAsync.UserName }); return(action); }
public async Task SendEmailActivationLinkAsync(User user, string plainPassword = null) { string tenancyName; if (user.EmailConfirmationCode.IsNullOrEmpty()) { throw new ApplicationException("EmailConfirmationCode should be set in order to send email activation link."); } if (user.TenantId.HasValue) { IRepository <Tenant> repository = this._tenantRepository; tenancyName = repository.Get(user.TenantId.Value).TenancyName; } else { tenancyName = null; } string str = tenancyName; string[] siteRootAddress = new string[] { this._webUrlService.GetSiteRootAddress(str), "Account/EmailConfirmation?userId=", null, null, null }; long id = user.Id; siteRootAddress[2] = Uri.EscapeDataString(SimpleStringCipher.Encrypt(id.ToString(), "gsKnGZ041HLL4IM8")); siteRootAddress[3] = "&confirmationCode="; siteRootAddress[4] = Uri.EscapeDataString(user.EmailConfirmationCode); string str1 = string.Concat(siteRootAddress); StringBuilder stringBuilder = new StringBuilder(this._emailTemplateProvider.GetDefaultTemplate()); int year = DateTime.Now.Year; stringBuilder.Replace("{CURRENT_YEAR}", year.ToString()); stringBuilder.Replace("{EMAIL_TITLE}", this.L("EmailActivation_Title")); stringBuilder.Replace("{EMAIL_SUB_TITLE}", this.L("EmailActivation_SubTitle")); StringBuilder stringBuilder1 = new StringBuilder(); string[] strArrays = new string[] { "<b>", this.L("NameSurname"), "</b>: ", user.Name, " ", user.Surname, "<br />" }; stringBuilder1.AppendLine(string.Concat(strArrays)); if (!str.IsNullOrEmpty()) { string[] strArrays1 = new string[] { "<b>", this.L("TenancyName"), "</b>: ", str, "<br />" }; stringBuilder1.AppendLine(string.Concat(strArrays1)); } string[] strArrays2 = new string[] { "<b>", this.L("UserName"), "</b>: ", user.UserName, "<br />" }; stringBuilder1.AppendLine(string.Concat(strArrays2)); if (!plainPassword.IsNullOrEmpty()) { string[] strArrays3 = new string[] { "<b>", this.L("Password"), "</b>: ", plainPassword, "<br />" }; stringBuilder1.AppendLine(string.Concat(strArrays3)); } stringBuilder1.AppendLine("<br />"); stringBuilder1.AppendLine(string.Concat(this.L("EmailActivation_ClickTheLinkBelowToVerifyYourEmail"), "<br /><br />")); string[] strArrays4 = new string[] { "<a href=\"", str1, "\">", str1, "</a>" }; stringBuilder1.AppendLine(string.Concat(strArrays4)); stringBuilder.Replace("{EMAIL_BODY}", stringBuilder1.ToString()); await this._emailSender.SendAsync(user.EmailAddress, this.L("EmailActivation_Subject"), stringBuilder.ToString(), true); }
public void ThrowInvalidSuperPasswordExceptionWhenSuperPasswordIsWrong() { var vault = new InMemoryVault(); var cipher = new SimpleStringCipher(); var container = new VaultSecureContainer(vault, cipher); var title = "Twitter"; var password = "******"; var superPassword = "******"; container.Store(title, password, superPassword); Assert.Throws <InvalidSuperPasswordException>(() => container.GetPassword(title, "wrong")); }
public void Should_Be_Able_To_Change_InitVector_And_Key() { const string initVectorString = "1234BCHF9876skd*"; const string myKey = "84ncpaKMC_!TuAna"; const string plainText = "This is a plain text!"; var cipher = new SimpleStringCipher { InitVectorBytes = Encoding.ASCII.GetBytes(initVectorString) }; var enryptedText = cipher.Encrypt(plainText, myKey); cipher.Decrypt(enryptedText, myKey).ShouldBe(plainText); }
public void GetPasswordProperlyReturnPasswordTest() { var vault = new InMemoryVault(); var cipher = new SimpleStringCipher(); var container = new VaultSecureContainer(vault, cipher); var title = "Twitter"; var password = "******"; var superPassword = "******"; container.Store(title, password, superPassword); var retrievedPassword = container.GetPassword(title, superPassword); Assert.Equal(password, retrievedPassword); }
public void GetTitlesIsSameAsVaultGetTitlesTest() { var vault = new InMemoryVault(); vault.Store(new VaultRecord { Title = "Test", CipherPassword = "******", Sign = "12ug30172hy012" }); var cipher = new SimpleStringCipher(); var container = new VaultSecureContainer(vault, cipher); Assert.Equal(vault.GetTitles(), container.GetTitles()); }
public virtual async Task <ActionResult> ResetPassword(ResetPasswordViewModel model) { CheckModelState(); _unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant); var userId = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId)); var user = await _userManager.GetUserByIdAsync(userId); if (user == null || user.PasswordResetCode.IsNullOrEmpty() || user.PasswordResetCode != model.ResetCode) { throw new UserFriendlyException(L("InvalidPasswordResetCode"), L("InvalidPasswordResetCode_Detail")); } return(View(model)); }
/// <summary> /// Send email activation link to user's email address. /// </summary> /// <param name="user">User</param> /// <param name="plainPassword"> /// Can be set to user's plain password to include it in the email. /// </param> public async Task SendEmailActivationLinkAsync(User user, string plainPassword = null) { if (user.EmailConfirmationCode.IsNullOrEmpty()) { throw new ApplicationException("EmailConfirmationCode should be set in order to send email activation link."); } var tenancyName = user.TenantId.HasValue ? _tenantRepository.Get(user.TenantId.Value).TenancyName : null; var link = _webUrlService.GetSiteRootAddress(tenancyName) + "Account/EmailConfirmation" + "?userId=" + Uri.EscapeDataString(SimpleStringCipher.Encrypt(user.Id.ToString())) + "&confirmationCode=" + Uri.EscapeDataString(user.EmailConfirmationCode); var emailTemplate = new StringBuilder(_emailTemplateProvider.GetDefaultTemplate()); emailTemplate.Replace("{EMAIL_TITLE}", L("EmailActivation_Title")); emailTemplate.Replace("{EMAIL_SUB_TITLE}", L("EmailActivation_SubTitle")); var mailMessage = new StringBuilder(); mailMessage.AppendLine("<b>" + L("NameSurname") + "</b>: " + user.Name + " " + user.Surname + "<br />"); if (!tenancyName.IsNullOrEmpty()) { mailMessage.AppendLine("<b>" + L("TenancyName") + "</b>: " + tenancyName + "<br />"); } mailMessage.AppendLine("<b>" + L("UserName") + "</b>: " + user.UserName + "<br />"); if (!plainPassword.IsNullOrEmpty()) { mailMessage.AppendLine("<b>" + L("Password") + "</b>: " + plainPassword + "<br />"); } mailMessage.AppendLine("<br />"); mailMessage.AppendLine(L("EmailActivation_ClickTheLinkBelowToVerifyYourEmail") + "<br /><br />"); mailMessage.AppendLine("<a href=\"" + link + "\">" + link + "</a>"); emailTemplate.Replace("{EMAIL_BODY}", mailMessage.ToString()); await _emailSender.SendAsync(user.EmailAddress, L("EmailActivation_Subject"), emailTemplate.ToString()); }
public void StoreFunctionInsertProperlyTheVaultRecordTest() { var vault = new InMemoryVault(); var cipher = new SimpleStringCipher(); var container = new VaultSecureContainer(vault, cipher); var title = "Twitter"; var password = "******"; var superPassword = "******"; container.Store(title, password, superPassword); var record = vault.Get("Twitter"); Assert.NotNull(record); Assert.Equal(title, record.Title); Assert.Equal(password, cipher.Decrypt(record.CipherPassword, superPassword)); Assert.Equal(cipher.CalculateHash(superPassword), record.Sign); }
public void RemoveTitleShouldRemoveRecordFromVaultIfPassowrdIsCorrect() { var vault = new InMemoryVault(); var cipher = new SimpleStringCipher(); var container = new VaultSecureContainer(vault, cipher); var title = "Twitter"; var password = "******"; var superPassword = "******"; container.Store(title, password, superPassword); Assert.True(container.GetTitles().Count() == 1); Assert.Throws <InvalidSuperPasswordException>(() => container.RemoveTitle(title, "wrong")); container.RemoveTitle(title, superPassword); Assert.True(container.GetTitles().Count() == 0); }
private void button_autologin_save_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox_username.Text) || (_cfg["Autologin"]["Enabled"] == "0" && string.IsNullOrEmpty(textBox_password.Text))) { if (string.IsNullOrEmpty(textBox_username.Text)) { textBox_username.Focus(); } else { textBox_password.Focus(); } return; } _cfg["Autologin"]["Enabled"] = "1"; _cfg["Autologin"]["Username"] = textBox_username.Text; if (!string.IsNullOrEmpty(textBox_password.Text)) { _cfg["Autologin"]["Password"] = SimpleStringCipher.Encrypt(textBox_password.Text, "OPENNOSROCKXXX"); } int tmp = Convert.ToInt32(numericUpDown_delay.Value); if (tmp < 750) { tmp = 1000; } else if (tmp > 10000) { tmp = 10000; } _cfg["Autologin"]["Delay"] = tmp.ToString(); _logInAs = textBox_username.Text; textBox_password.Text = ""; button_back_Click(sender, null); }
private void button_gamestart_Click(object sender, EventArgs e) { button_gamestart.Enabled = false; try { Process[] processesNt = Process.GetProcessesByName("Nostale.dat"); Process[] processesNtx = Process.GetProcessesByName("NostaleX.dat"); Process[] processesOn = Process.GetProcessesByName("NostaleOpen.dat"); if (processesNt.Length > 0 || processesOn.Length > 0 || processesNtx.Length > 0) { // There is already an instance running MessageBox.Show(_l.T("ONLYONEINSTANCE"), _l.T("ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { IPAddress[] hostAddresses = Dns.GetHostAddresses(textBox_server.Text); IPAddress ipAddress = hostAddresses.Contains(IPAddress.Parse("127.0.0.1")) ? IPAddress.Parse("127.0.0.1") : hostAddresses[0]; int port = 4000 + _l.Lng.GetHashCode(); if (!string.IsNullOrEmpty(_cfg["Form"]["OverridePort"])) { int.TryParse(_cfg["Form"]["OverridePort"], out port); } else { _cfg["Form"]["OverridePort"] = ""; } string result = NosModder.GoWithIniFile(_cfg["Graph"]["Mode"] != "GL", ipAddress.ToString(), port); if (result != "ok") { MessageBox.Show(_l.T(result), _l.T("Fehler"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Hide(); int tmp; int.TryParse(_cfg["Autologin"]["Delay"], out tmp); if (tmp < 750) { tmp = 1250; } else if (tmp > 10000) { tmp = 10000; } _cfg["Autologin"]["Delay"] = tmp.ToString(); string password = ""; try { password = SimpleStringCipher.Decrypt(_cfg["Autologin"]["Password"], "OPENNOSROCKXXX"); } catch (Exception exception) { MessageBox.Show(exception.ToString(), _l.T("ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } Thread.Sleep(3000); if (_cfg["Autologin"]["Enabled"] != "0") { NosModder.SendCredentials(textBox_username.Text, password, _cfg); } Application.Exit(); } } catch (Exception exception) { MessageBox.Show(exception.ToString(), _l.T("ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), _l.T("Fehler"), MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } button_gamestart.Enabled = true; }
public virtual async Task <JsonResult> Login(LoginViewModel loginModel, string returnUrl = "", string returnUrlHash = "") { JsonResult jsonResult; this.CheckModelState(); IActiveUnitOfWork current = this._unitOfWorkManager.Current; current.DisableFilter(new string[] { "MayHaveTenant" }); AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult loginResultAsync = await this.GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, loginModel.TenancyName); AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult abpLoginResult = loginResultAsync; if (!abpLoginResult.User.ShouldChangePasswordOnNextLogin) { await this.SignInAsync(abpLoginResult.User, abpLoginResult.Identity, loginModel.RememberMe); if (string.IsNullOrWhiteSpace(returnUrl)) { returnUrl = this.Url.Action("Index", "Application"); } if (!string.IsNullOrWhiteSpace(returnUrlHash)) { returnUrl = string.Concat(returnUrl, returnUrlHash); } FuelWerx.Authorization.Users.User user = await this._userManager.FindByNameOrEmailAsync(loginModel.UsernameOrEmailAddress.ToString()); FuelWerx.Authorization.Users.User user1 = user; if (user1 != null) { string userPostLoginViewType = await this._userAppService.GetUserPostLoginViewType(user1.Id); if (!string.IsNullOrEmpty(userPostLoginViewType)) { this.Session.Add("PostLoginRedirectCheck", userPostLoginViewType); } bool flag = await this._userAppService.ShowScreencastAtLogin(user1.Id); if (flag) { this.Session.Add("ShowScreencastAtLoginCheck", flag); } } AccountController accountController = this; MvcAjaxResponse mvcAjaxResponse = new MvcAjaxResponse() { TargetUrl = returnUrl }; jsonResult = accountController.Json(mvcAjaxResponse); } else { abpLoginResult.User.SetNewPasswordResetCode(); AccountController accountController1 = this; MvcAjaxResponse mvcAjaxResponse1 = new MvcAjaxResponse(); UrlHelper url = this.Url; ResetPasswordViewModel resetPasswordViewModel = new ResetPasswordViewModel(); long id = abpLoginResult.User.Id; resetPasswordViewModel.UserId = SimpleStringCipher.Encrypt(id.ToString(), "gsKnGZ041HLL4IM8"); resetPasswordViewModel.ResetCode = abpLoginResult.User.PasswordResetCode; mvcAjaxResponse1.TargetUrl = url.Action("ResetPassword", resetPasswordViewModel); jsonResult = accountController1.Json(mvcAjaxResponse1); } return(jsonResult); }