public void RecoverPassword(string UserName, string Email) { if (_dbContext.Login.Where(l => l.UserName == UserName).Count() == 0) { throw new Exception("Er is geen account met deze gebruikersnaam bij ons bekent."); } if (_dbContext.User.Where(u => u.Email == Email).Count() == 0) { throw new Exception("Er is geen account met deze email bij ons bekent."); } if (_dbContext.User.Where(u => u.Email == Email).First().LoginID != _dbContext.Login.Where(l => l.UserName == UserName).First().ID) { throw new Exception("De gebruikersnaam en het email adres komt niet overeen"); } Models.DataModels.Login Login = _dbContext.Login.Where(l => l.UserName == UserName).First(); string NewPassword = "******"; string EncryptedNewPassword = EncryptHandler.Encrypt(NewPassword, Login.Salt); Login.Password = EncryptedNewPassword; _dbContext.SaveChanges(); EmailHandler EmailHandler = new EmailHandler(); string Message = "Beste " + UserName + "," + Environment.NewLine + Environment.NewLine + "Je hebt op onze site een niew wachtwoord aangevraagd." + Environment.NewLine + "Jouw niew wachtwoord is : " + NewPassword + Environment.NewLine + Environment.NewLine + "Met Vriendelijke Groet" + Environment.NewLine + "BrightLearn"; EmailHandler.SendEmail(Email, "Wachtwoord herstel", Message); }
public User GenerateUser() { string UserName = ""; while (true) { UserName = RandomString(5); if (dbContext.Login.Where(l => l.UserName == UserName).Count() == 0) { break; } } string Password = "******"; string SaltKey = EncryptHandler.RandomString(8); Models.DataModels.Login login = new Models.DataModels.Login() { UserName = UserName, Password = Password, Salt = SaltKey }; dbContext.SaveChanges(); int loginID = dbContext.Login.Last().ID; //SQL.Insert("INSERT INTO `login` (`ID`, `username`, `password`, `salt`) VALUES (NULL, '" + UserName + "', '" + EncryptHandler.Encrypt(Password, SaltKey) + "', '" + SaltKey + "');"); //string loginID = SQL.Select("SELECT `ID` FROM `login` WHERE `username` = '"+UserName+"'")[0]; Models.DataModels.User user = new Models.DataModels.User() { Email = "*****@*****.**", FirstName = "Voornaam", LastName = "Achternaam", LoginID = loginID, Type = "user" }; dbContext.User.Add(user); dbContext.SaveChanges(); //SQL.Insert("INSERT INTO `user` (`ID`, `loginID`, `email`, `firstName`, `middleName`, `lastName`, `type`) VALUES (NULL, '"+loginID+"', '*****@*****.**', 'Voornaam', NULL, 'Achternaam', 'user');"); return(new User() { UserName = UserName, Password = Password }); }
public User GenerateUser() { string UserName = ""; while (true) { UserName = RandomString(5); if (_dbContext.Login.Where(l => l.UserName == UserName).Count() == 0) { break; } } string Password = "******"; string SaltKey = EncryptHandler.RandomString(8); string newPass = EncryptHandler.Encrypt(Password, SaltKey); Models.DataModels.Login login = new Models.DataModels.Login() { UserName = UserName, Password = newPass, Salt = SaltKey }; _dbContext.Login.Add(login); _dbContext.SaveChanges(); login = _dbContext.Login.OrderByDescending(u => u.ID).FirstOrDefault(); Models.DataModels.User User = new Models.DataModels.User() { Email = "*****@*****.**", FirstName = "Voornaam", LastName = "Achternaam", LoginID = login.ID, Type = "user" }; _dbContext.User.Add(User); _dbContext.SaveChanges(); return(new User() { UserName = UserName, Password = Password }); }
public string EncryptPass(string Password, string UserName) { return(EncryptHandler.Encrypt(Password, _dbContext.Login.Where(l => l.UserName == UserName).First().Salt)); }