public static async Task <bool> CheckLogin(Action callback, MainWindow mw, Uri ApiUrl) { if (App.Token == default) { if (string.IsNullOrWhiteSpace(Settings.Default.Username) || string.IsNullOrWhiteSpace(Settings.Default.Password)) { mw.Dispatcher.Invoke(() => { LoginDialog ld = new LoginDialog(ApiUrl, callback); }); return(false); } string login = Settings.Default.Username; string passwd = PasswordEncryptor.Decrypt(Settings.Default.Password, login.Trim()); ObjectResult <LoginContent> result = await WebWrapper.Login(login, passwd, ApiUrl); if (result == null || !IsSuccessStatusCode(result.code) || result.content == null || result.content.privileges < 0) { mw.Dispatcher.Invoke(() => { LoginDialog ld = new LoginDialog(ApiUrl, callback); }); return(false); } LoginContent loginContent = result.content; App.Token = loginContent.token; } if (!mw.ReportedDLC) { mw.ReportDLC(); } return(true); }
private void CheckUserArrivalTime(User user, dbDataContext db) { var decryptedSystemPassword = PasswordEncryptor.Decrypt(user.SystemPassword); var decryptedSystemNumber = PasswordEncryptor.Decrypt(user.SystemNumber); var today = DateTime.Today; var loginParameters = new HappyHoursLoginParameters() { Credentials = new HappyHoursCredentials() { Username = user.SystemEmail, Password = decryptedSystemPassword, Number = decryptedSystemNumber }, StartDate = new DateTime(today.Year, today.Month, today.Day), EndDate = new DateTime(today.Year, today.Month, today.Day) }; HappyHoursCoreBL manager = new HappyHoursCoreBL(); HappyHourSummary summaryResult = manager.GetSummary(loginParameters); var dayHour = summaryResult.DayDetails.FirstOrDefault(); if (dayHour == null) { return; } HandleUserTime(user, dayHour, summaryResult.User, db); }
public ActionResult Profile(long UserId) { var user = _dbContext.Users.Where(x => x.ID == UserId).FirstOrDefault(); var decryptedPass = PasswordEncryptor.Decrypt(user.Password); ViewBag.pass = decryptedPass; return(View(user)); }
public void EncryptDecryptByPassword_different_instance_default_AesCryptoServiceProvider() { //ARRANGE var encryptor = new PasswordEncryptor(); var decryptor = new PasswordEncryptor(); var plainTextSource = "Test data to encrypt"; var result = String.Empty; byte[] salt; //ACT var encrypted = encryptor.Encrypt("Password1", plainTextSource, out salt); result = decryptor.Decrypt("Password1", salt, encrypted); //ASSERT Assert.AreEqual(plainTextSource, result); }
public ActionResult Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } var user = _userRepository.GetAll().Where(x => x.Name == model.Name).SingleOrDefault(); if (user != null) { var decryptedPassword = PasswordEncryptor.Decrypt(user.Password); if (model.Password == decryptedPassword) { Session["UserName"] = model.Name; return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); }
public UserInformationResponse GetUserInformation(UserInformationRequest request, long userId, dbDataContext db) { var user = GetUserDetails(userId, db); int month = 0; if (request == null || request.Month == null) { month = DateTime.Today.Month; } else { month = request.Month.Value; } //var today = DateTime.Today; // new DateTime(2017, 8, 1).Date; var startDate = new DateTime(DateTime.Today.Year, month, 1); int daysInMonth = 0; if (month == DateTime.Today.Month) { daysInMonth = DateTime.Today.Day; } else { daysInMonth = DateTime.DaysInMonth(DateTime.Today.Year, month); } var endDate = new DateTime(DateTime.Today.Year, month, daysInMonth); var decryptedSystemPassword = PasswordEncryptor.Decrypt(user.SystemPassword); var decryptedSystemNumber = PasswordEncryptor.Decrypt(user.SystemNumber); var loginParameters = new HappyHoursLoginParameters() { Credentials = new HappyHoursCredentials() { Username = user.SystemEmail, Password = decryptedSystemPassword, Number = decryptedSystemNumber }, StartDate = startDate, EndDate = endDate //today // new DateTime(2017, 8, 31).Date }; HappyHoursCoreBL manager = new HappyHoursCoreBL(); HappyHourSummary summaryResult = manager.GetSummary(loginParameters); IList <MonthDetails> months = new List <MonthDetails>(); CultureInfo usEnglish = new CultureInfo("en-US"); for (var i = 1; i <= DateTime.Today.Month; i++) { months.Add(new MonthDetails() { Month = i, Name = usEnglish.DateTimeFormat.GetMonthName(i) }); } return(new UserInformationResponse() { FirstName = user.FirstName, LastName = user.LastName, ExtraMinutes = summaryResult.ExtraMinutes, LackMinutes = summaryResult.LackMinutes, Days = summaryResult.DayDetails.Select(c => new DayTimeDetails() { ExtraMinutes = c.ExtraMinutes, LackMinutes = c.LackMinutes, Date = HappyHourTimestampProvider.GetDateTimestamp(c.Date), StartTime = HappyHourTimestampProvider.GetDateTimeTimestamp(c.StartTime), EndTime = HappyHourTimestampProvider.GetDateTimeTimestamp(c.EndTime), Day = c.Day }).ToList(), Months = months }); }