public async Task <bool> RemoveCode(PasswordCode psd) { getContext().Remove(psd); await getContext().SaveChangesAsync(); return(true); }
public void PasswordHasSymbolsAndLowerLetters() { var symbols = new[] { '!', '@', '#' }; var pass = PasswordCode.CreatePassword(PasswordLength, false, false, symbols); Assert.IsTrue(pass.All(x => char.IsLower(x) || symbols.Contains(x))); }
public async Task <bool> InserCode(PasswordCode passwordCode) { await getContext().AddAsync(passwordCode); await getContext().SaveChangesAsync(); return(true); }
public void SimplestPasswordIsWorking() { var pass = PasswordCode.CreatePassword(5, false, false, new char[0]); Assert.IsNotNull(pass); Assert.IsInstanceOfType(pass, typeof(string)); Assert.IsTrue(pass.Length == 5); }
public void PasswordHasEverything() { var symbols = new[] { '!', '@', '#' }; var pass = PasswordCode.CreatePassword(PasswordLength, true, true, symbols); Assert.IsTrue(pass.Any(char.IsLower)); Assert.IsTrue(pass.Any(char.IsDigit)); Assert.IsTrue(pass.Any(char.IsUpper)); Assert.IsTrue(pass.Any(x => symbols.Contains(x))); }
public async Task <IActionResult> UpdatePassword(string Code, string Password) { PasswordCode psd = await getDao().getPasswordCode(Code); if (psd != null) { User user = await getDao().GetUser(psd.UserId); user.Password = Password; await getDao().Modify(user); await getDao().RemoveCode(psd); } return(RedirectToAction(nameof(Index))); }
public IHttpActionResult ChangePassword(ChangePasswordModel model) { var UserExist = AuthDB.Users.Where(u => u.PhoneNumber == model.Phone).FirstOrDefault(); if (UserExist == null) { return(BadRequest("Invalid Phone number")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } PasswordCode passwordCode = db.PasswordCodes.Where(p => p.Code == model.Code && p.Phone == model.Phone).FirstOrDefault(); if (passwordCode == null) { return(BadRequest("Invalid Code")); } TimeSpan t = DateTime.Now - passwordCode.Time; if (t.TotalMinutes > 30) { return(BadRequest("This code is expired")); } var user = AuthDB.Users.Where(u => u.PhoneNumber == model.Phone).FirstOrDefault(); try { UserStore <ApplicationUser> store = new UserStore <ApplicationUser>(new ApplicationDBContext()); UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(store); var newPasswordHash = manager.PasswordHasher.HashPassword(model.Password); store.SetPasswordHashAsync(user, newPasswordHash); //UserExist.FirstOrDefault().PasswordHash = newPasswordHash; AuthDB.SaveChanges(); return(Ok("Done")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult PasswordCode(string PhoneNumber) { var UserExist = AuthDB.Users.Where(u => u.PhoneNumber == PhoneNumber).FirstOrDefault(); if (UserExist == null) { return(BadRequest("invalid Phone Number")); } var oldCode = db.PasswordCodes.Where(c => c.Phone == PhoneNumber); if (oldCode != null) { foreach (var item in oldCode) { db.PasswordCodes.Remove(item); } } var deviceId = UserExist.DeviceToken; Random _rdm = new Random(); var Code = _rdm.Next(1000, 9999); var input = new NotificationViewModel() { Title = "يرجى استخدام كود التفعيل", Msg = Code.ToString() }; try { var PasswordCode = new PasswordCode() { Code = Code.ToString(), Phone = PhoneNumber, Time = DateTime.Now }; db.PasswordCodes.Add(PasswordCode); db.SaveChanges(); PushNotification p = new PushNotification(input, deviceId); return(Ok(Code)); } catch (Exception e) { return(BadRequest(e.Message)); } }
private bool PasswordCodeValid(string code, string username) { TimeSpan aliveTime = TimeSpan.FromHours(PASSWORD_RESET_CODE_ALIVE_TIME); try { PasswordCode result = (from p in _context.PasswordCode where p.Username == username select p).SingleOrDefault(); if (result != null) { if (result.Code == code && result.Username == username && result.IsUsed == false && DateTime.Now - result.TimeStamp < aliveTime)// oikea palautus koodi, username, voimassaolokoodi ja aika aloitusaika - nyt aika < olemassaoloaika { //var time = DateTime.Now - result.TimeStamp; result.IsUsed = true;//koodi käytetty _context.SaveChanges(); return(true); } } } catch (Exception) { } return(false); }
public void Update(PasswordCode passwordCode) { _passwordCodeDal.Update(passwordCode); }
public IActionResult ForgotPw(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var ad = adHelper.GetAllUsers(); var user = ad.Find(x => x.Email.ToLower() == model.Email.ToLower()); if (user == null) { return(RedirectToAction(nameof(ForgotPasswordConfirmation))); } else { MailMessage mail = new MailMessage { Subject = "mokkamoi!!", From = new MailAddress("*****@*****.**") }; ApplicationUser userA = new ApplicationUser(); userA.UserName = user.Username; Guid g = Guid.NewGuid(); string GuidString = Convert.ToBase64String(g.ToByteArray()); GuidString = GuidString.Replace("=", ""); GuidString = GuidString.Replace("+", ""); var callbackUrl = Url.ResetPasswordCallbackLink(user.Username, GuidString, Request.Scheme); try { PasswordCode result = (from p in _context.PasswordCode where p.Username == user.Username select p).SingleOrDefault(); if (result == null)//jos käyttäjä ei ole ennen tehnyt salasananpalautusta tehdään uusi passwordcode { result = new PasswordCode { Username = user.Username }; } result.Code = GuidString;// tallennetaan käyttäjälle salasanan palautus tiedot result.IsUsed = false; result.TimeStamp = DateTime.Now; _context.Update(result); _context.SaveChanges(); } catch (Exception) { } mail.To.Add(user.Email); mail.Body = $"Reset password link: {callbackUrl}"; mail.IsBodyHtml = true; adHelper.SendMail(mail, user.Email); } return(RedirectToAction(nameof(ForgotPasswordConfirmation))); } // If we got this far, something failed, redisplay form return(View()); }
public void PasswordHasDigitsAndUpperLetters() { var pass = PasswordCode.CreatePassword(PasswordLength, true, true, new char[0]); Assert.IsTrue(pass.Any(char.IsDigit) && pass.Any(char.IsUpper)); }
public void PasswordHasDigits() { var pass = PasswordCode.CreatePassword(PasswordLength, false, true, new char[0]); Assert.IsTrue(pass.Any(char.IsDigit)); }
public void PasswordHasOnlyLowerLetters() { var pass = PasswordCode.CreatePassword(PasswordLength, false, false, new char[0]); Assert.IsTrue(pass.All(char.IsLower)); }
public void ShowPasswordCode(bool active) { PasswordCode.SetActive(active); }
public static Page Fetch(Service service) { if (!Platform.HasInternetConnection()) { return new ContentPage { Content = new Label { Text = Localize.GetString("TelegramPleaseConnectToInternet"), VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, XAlign = TextAlignment.Center, Font = Font.SystemFontOfSize(18), }, Title = Localize.GetString("TelegramSetupWizardTitle"), Padding = 30, }; } LoadSettingsIfNeeded(); if (_cachedPage != null) { return _cachedPage; } var tabs = new TabbedPage(); var userInformation = new UserInformation(service, tabs); var passwordCode = new PasswordCode(service, tabs, userInformation); var password = new Password(service, tabs, passwordCode); var code = new Code(service, tabs, password, userInformation); var info = new Info(service, tabs, code); tabs.Children.Add(info); tabs.PropertyChanged += (sender, e) => { if (e.PropertyName == "CurrentPage") { var selected = tabs.CurrentPage; if (selected is Info) { tabs.Children.Remove(code); tabs.Children.Remove(password); tabs.Children.Remove(passwordCode); tabs.Children.Remove(userInformation); } if (selected is Code) { tabs.Children.Remove(password); tabs.Children.Remove(passwordCode); tabs.Children.Remove(userInformation); } if (selected is Password) { tabs.Children.Remove(passwordCode); tabs.Children.Remove(userInformation); } if (selected is PasswordCode) { tabs.Children.Remove(userInformation); } } }; tabs.Title = Localize.GetString("TelegramSetupWizardTitle"); _cachedPage = tabs; return tabs; }
public void Add(PasswordCode passwordCode) { _passwordCodeDal.Add(passwordCode); }
public Password(Service service, TabbedPage tabs, PasswordCode passwordCode) { _service = service; _passwordLabel = new Label(); _passwordLabel.VerticalOptions = LayoutOptions.CenterAndExpand; _passwordLabel.Text = Localize.GetString("TelegramEnterPassword"); _passwordLabel.IsVisible = true; _passwordLabel.Font = Font.SystemFontOfSize(18); _passwordLabel.XAlign = TextAlignment.Center; _password = new Entry(); _password.IsPassword = true; _password.Placeholder = Localize.GetString("TelegramPassword"); _finish = new Button(); _finish.Text = Localize.GetString("TelegramFinish"); _finish.TextColor = Color.White; _finish.BackgroundColor = Color.FromHex("77D065"); _finish.Clicked += async (sender, e) => { _password.IsEnabled = false; _finish.IsEnabled = false; _progressBar.IsVisible = true; DependencyService.Get<IPluginPageControls>().BackPressEnabled = false; tabs.IsEnabled = false; var password = _password.Text; if (string.IsNullOrEmpty(password)) { await DisplayAlert(Localize.GetString("TelegramInvalidPassword"), Localize.GetString("TelegramInvalidPasswordDetail"), Localize.GetString("TelegramOkay")); } var result = await VerifyPassword(password); password = null; _password.IsEnabled = true; _finish.IsEnabled = true; _progressBar.IsVisible = false; DependencyService.Get<IPluginPageControls>().BackPressEnabled = true; tabs.IsEnabled = true; if (result.Success) { Save(service, result.AccountId, GetSettingsTelegramSettings(NationalNumber)); DependencyService.Get<IPluginPageControls>().Finish(); } else { _error.Text = result.ErrorMessage; } }; _error = new Label(); _error.VerticalOptions = LayoutOptions.EndAndExpand; _error.IsVisible = false; _error.Font = Font.SystemFontOfSize(18); _error.XAlign = TextAlignment.Center; _error.TextColor = Color.Red; _forgotPassword = new Button(); _forgotPassword.VerticalOptions = LayoutOptions.EndAndExpand; _forgotPassword.Text = Localize.GetString("TelegramForgotPassword"); _forgotPassword.TextColor = Color.White; _forgotPassword.BackgroundColor = Color.FromHex("77D065"); _forgotPassword.Clicked += async (sender, e) => { _password.IsEnabled = false; _finish.IsEnabled = false; _progressBar.IsVisible = true; DependencyService.Get<IPluginPageControls>().BackPressEnabled = false; tabs.IsEnabled = false; var result = await RecoverPassword(); _password.IsEnabled = true; _finish.IsEnabled = true; _progressBar.IsVisible = false; DependencyService.Get<IPluginPageControls>().BackPressEnabled = true; tabs.IsEnabled = true; if (result != null) { passwordCode.CountryCode = CountryCode; passwordCode.NationalNumber = NationalNumber; passwordCode.EmailPattern = result.EmailPattern; passwordCode.Code = Code; tabs.Children.Add(passwordCode); tabs.CurrentPage = passwordCode; } }; _progressBar = new ActivityIndicator(); _progressBar.VerticalOptions = LayoutOptions.CenterAndExpand; _progressBar.IsRunning = true; _progressBar.IsVisible = false; var stackLayout = new StackLayout(); stackLayout.Spacing = 20; stackLayout.Padding = 25; stackLayout.VerticalOptions = LayoutOptions.Start; var children = stackLayout.Children; children.Add(_passwordLabel); children.Add(_password); children.Add(_finish); children.Add(_error); children.Add(_progressBar); children.Add(_forgotPassword); Content = new ScrollView { Content = stackLayout }; Title = Localize.GetString("TelegramPasswordTitle"); }