public ActionResult Registration(Models.UserModel user) { if (ModelState.IsValid) { using (var db= new MusicStoreContext()) { var crypto = new SimpleCrypto.PBKDF2(); var encrypPass = crypto.Compute(user.Password); var sysUser = db.User.Create(); sysUser.Email = user.Email; sysUser.Password = encrypPass; sysUser.PasswordSalt = crypto.Salt; db.User.Add(sysUser); db.SaveChanges(); return RedirectToAction("List", "Product"); } } return View(user); }
public ActionResult Login(Login l, string ReturnUrl = "") { var crypto = new SimpleCrypto.PBKDF2(); var user = repository.Users.Where(a => a.email.Equals(l.email)).FirstOrDefault(); if (user != null) { if (user.password == crypto.Compute(l.password, user.passwordSalt)) { FormsAuthentication.SetAuthCookie(user.userID.ToString(), l.RememberMe); if (Url.IsLocalUrl(ReturnUrl)) { return Redirect(ReturnUrl); } else { return RedirectToAction("Mapping", "MappingProducts/Mapping"); } } } else { ModelState.Remove("Password"); ViewBag.Message = "Невірний логін або пароль"; } return View(); }
public ActionResult MailConfig(Models.ConfigDetailsModel MailConfig) { if (ModelState.IsValid) { using (var db = new MailAppDBEntities()) { var ConfigDetails = db.ConfigDetails.Create(); var Crypto = new SimpleCrypto.PBKDF2(); var encPass = Crypto.Compute(MailConfig.Password); var user = db.Users.FirstOrDefault(u => u.Email == this.HttpContext.User.Identity.Name); if (user != null) { ConfigDetails.SMTPHost = MailConfig.SMTPHost; ConfigDetails.SMTPPort = MailConfig.SMTPPort; ConfigDetails.Password = MailConfig.Password; ConfigDetails.PasswordSalt = Crypto.Salt; ConfigDetails.UserID = user.UserID; db.ConfigDetails.Add(ConfigDetails); db.SaveChanges(); return RedirectToAction("Index", "Home"); } return View(ConfigDetails); } } else { ModelState.AddModelError("", "Login Data is incorrect"); } return View(); }
public ActionResult Register(Models.UserModel user) { if (ModelState.IsValid) { using (var db = new CustomLogin_MVCContext()) { var crypto = new SimpleCrypto.PBKDF2(); var encrypPass = crypto.Compute(user.Password); var newUser = db.UserModels.Create(); newUser.Email = user.Email; newUser.Password = encrypPass; newUser.PasswordSalt = crypto.Salt; newUser.Id = Guid.NewGuid(); db.UserModels.Add(newUser); db.SaveChanges(); return RedirectToAction("Index", "User"); } } else { ModelState.AddModelError("", "Data is not correct"); } return View(); }
public HttpResponseMessage PutUser(Guid id, User user) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != user.UserId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(user).State = EntityState.Modified; try { var crypto = new SimpleCrypto.PBKDF2(); var encryptedPassword = crypto.Compute(user.Password); user.ApproverID = 1; user.Password = encryptedPassword; user.PasswordSalt = crypto.Salt; db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
public ActionResult Create([Bind(Include = "ID,BedrijfID,Email,Password")] Gebruiker gebruiker) { try { if (ModelState.IsValid) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(gebruiker.Password); gebruiker.Password = encrpPass; gebruiker.PasswordSalt = crypto.Salt; db.Gebruikers.Add(gebruiker); db.SaveChanges(); return RedirectToAction("Login", "Home"); } } catch(DbUpdateException ex ) { System.Diagnostics.Debug.Write("Error writing to database: " + ex.Message); ModelState.AddModelError("", "Dit emailadres wordt al gebruikt!"); } gebruiker.Password = null; gebruiker.PasswordSalt = null; ViewBag.BedrijfID = new SelectList(db.Bedrijven, "ID", "Naam", gebruiker.BedrijfID); return View(gebruiker); }
public bool IsExist(string xUserName, string xSenha) { try { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new PortalEntities()) { var user = db.tb_usuario.FirstOrDefault(x => x.xUserName == xUserName); if (user != null) { string sResult = crypto.Compute(xSenha, user.xSenhaSalt); if (user.xSenha == sResult) { IsValid = true; } } } return IsValid; } catch (Exception) { return false; } }
public ActionResult Registration(Models.UserModel user) { if (ModelState.IsValid) { using (var db = new MainDbContent()) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); var sysUser = db.SystemUsers.Create(); sysUser.Email = user.Email; sysUser.Password = encrpPass; sysUser.PasswordSalt = crypto.Salt; sysUser.UserId = Guid.NewGuid(); db.SystemUsers.Add(sysUser); db.SaveChanges(); SendMail(user); return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "Login Data is incorrect"); } return View(user); }
public ActionResult Registration(LoginSystem.Models.UserModel user) { if (ModelState.IsValid) { var db = new MainDbEntities(); try { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); var sysUser = db.SystemUsers.Create(); sysUser.Email = user.Email; sysUser.Password = encrpPass; sysUser.PasswordSalt = crypto.Salt; sysUser.UserId = "2"; db.Configuration.ValidateOnSaveEnabled = false; db.SystemUsers.Add(sysUser); db.SaveChanges(); return RedirectToAction("Index", "Home"); } finally { } } else { ModelState.AddModelError("","Log in data is incorrect"); } return View(user); }
public ActionResult Registration(Models.UserModel user) { using (var db = new MainDbEntities()) { if (ModelState.IsValid) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); var sysUser = db.SystemUsers.Create(); sysUser.Emal = user.Email; sysUser.Password = encrpPass; sysUser.PasswordSalt = crypto.Salt; sysUser.UserId = Guid.NewGuid(); db.SystemUsers.Add(sysUser); db.SaveChanges(); return RedirectToAction("Home", "Home"); } } return View(user); }
public ActionResult ChangePassword(Models.ChangePasswordModel pw) { String currentUser = User.Identity.Name; if (ModelState.IsValid) { using (var db = new MainDbEntities()) { var crypto = new SimpleCrypto.PBKDF2(); if (pw.ConfirmPassword.Equals(pw.NewPassword)) { if (IsVaild(currentUser,pw.OldPassword)) { User sysUser = db.Users.FirstOrDefault(m => m.UserName == currentUser); var encrpPass = crypto.Compute(pw.NewPassword); sysUser.Password = encrpPass; sysUser.PasswordSalt = crypto.Salt; db.SaveChanges(); } } return RedirectToAction("PasswordChangeOk", "Account"); } } return View(); }
public static bool IsValid(Users user, string password) { var isValid = false; var crypto = new SimpleCrypto.PBKDF2 {Salt = user.PasswordSalt}; var enteredPassword = crypto.Compute(password); if (enteredPassword == user.Password) isValid = true; return isValid; }
public string Register(User user, IEnumerable<string> selectedCities) { StringBuilder sb = new StringBuilder(); if (selectedCities == null) { sb.Append("No cities are selected"); } else { sb.Append(string.Join("", selectedCities)); if (ModelState.IsValid) { var crypto = new SimpleCrypto.PBKDF2(); var encrpass = crypto.Compute(user.password); user.password = encrpass; User user2 = null; user2 = repository.Users.Where(u => u.email == user.email || u.password == user.password || u.companyName == user.companyName).FirstOrDefault(); if (user2 == null) { user.passwordSalt = crypto.Salt; user.merchantLicense = false; user.tradeLicense = false; user.userGroupID = 3; repository.SaveUser(user); foreach (string item in selectedCities) { ChoosedCategory ck = new ChoosedCategory(); ck.userID = user.userID; ck.productCategoryID = Convert.ToInt32(item); repository.SaveChoosedCategory(ck); } ModelState.Clear(); ViewBag.Message = "Реєстрація прошла успішно!"; } else { ModelState.AddModelError(" ", "Користувач уже існує!"); ViewBag.Message = "Користувач уже існує!"; } } else { ViewBag.Message = "Перевірте поля!"; } } RedirectToAction("Index"); return sb.ToString(); }
public static bool IsValid(Users user, string password) { bool isValid = false; var crypto = new SimpleCrypto.PBKDF2(); if (user.Password == crypto.Compute(password,user.PasswordSalt)) { isValid = true; } return isValid; }
public ActionResult Register(RegisterModel registerModel) { if (ModelState.IsValid) { var checkUsername = RegisterRepository.CheckIfUsernameExists(registerModel.RegisterUsername); if (checkUsername != null) { ModelState.AddModelError("NameTaken", "Användarnamnet finns redan"); return View(); } var checkIfEmailExists = RegisterRepository.CheckIfEmailExists(registerModel.RegisterEmail); if (checkIfEmailExists != null) { ModelState.AddModelError("EmailTaken", "Emailadressen finns redan registrerad"); return View(); } //Encrypts the password var crypto = new SimpleCrypto.PBKDF2(); var encryptedPassword = crypto.Compute(registerModel.Registerpassword); //Creates an new usermodel and sets the values var registerUser = new User { Password = encryptedPassword, PasswordSalt = crypto.Salt, Username = registerModel.RegisterUsername, Email = registerModel.RegisterEmail, Gender = registerModel.Gender, Birthdate = registerModel.BirthDate }; //registers the user RegisterRepository.RegisterUser(registerUser); //Sets the subject and the body for the confirmation email string subject = "Tack för registreringen hos SuperAtleten"; string mailbody= "Hej " + registerModel.RegisterUsername + "<br /> Tack för att du registrerat dig hos " + "oss , vi hoppas att du kommer att tycka om vår tjänst. <br /><hr />"+ "Dina inloggningsuppgifter <br />" + "E-mail : " + registerModel.RegisterEmail + "<br />" + "Lösenord : " + registerModel.Registerpassword; //sends the email MailSender.sendMail(subject,mailbody,registerModel.RegisterEmail); TempData["Message"] = "Registreringen lyckades , Du kan nu logga in med dina användaruppgifter."; return RedirectToAction("Index", "Home"); } ModelState.AddModelError("RegisterFail", " - Registreringen misslyckades!"); return View(); }
/// <summary> /// Checked of de username en password kloppen /// </summary> /// <param name="firstname"></param> TODO Aanpassen naar email na aanpassen model en database /// <param name="lastname"></param> TODO /// <param name="password">Het opgegeven wachtwoord</param> /// <returns>Returns een geldig geauthenticeerd gebruikermodel, of null wanneer de gebruiker niet geauthenticeerd kan worden.</returns> public Gebruiker IsValid( string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); var user = db.Gebruikers.FirstOrDefault(u => u.Email == email); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { return user; } } return null; }
private bool IsValid(String email, String password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; using (var db = new MainDbEntities()) { var user = db.SystemUsers.FirstOrDefault(u => u.email == email); if (user != null) { if (user.password == crypto.Compute(password, user.passwordsalt)) { isValid = true; } } } return isValid; }
public ActionResult Index(user user, string userBirth) { var userSession = (user)Session["user"]; user.email = userSession.email; DateTime newBirthDate = Convert.ToDateTime(userBirth); UserPanel modelPanel = new UserPanel(); using (var db = new HotelDBEntities()) { user currentUser = db.users.FirstOrDefault(u => u.email == user.email); if (String.IsNullOrEmpty(user.name) || String.IsNullOrEmpty(user.surname)) { modelPanel.user = currentUser; modelPanel.info.type = 0; modelPanel.info.text = "You didn't fill name or surname, please fill those fields."; return View(modelPanel); } if (!(String.IsNullOrEmpty(user.password)) && (user.password.Length > 10 || user.password.Length < 6)) { modelPanel.user = currentUser; modelPanel.info.type = 0; modelPanel.info.text = "Password must be between 6 and 10 characters."; return View(modelPanel); } if (!(String.IsNullOrEmpty(user.password)) && (user.password.Length < 10 || user.password.Length > 6)) { var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(user.password); currentUser.password = encrPass; currentUser.password_salt = crypto.Salt; } currentUser.name = user.name; currentUser.surname = user.surname; currentUser.country = user.country; currentUser.birth_date = newBirthDate; db.users.Attach(currentUser); db.Entry(currentUser).Property(p => p.password).IsModified = true; db.Entry(currentUser).Property(p => p.password_salt).IsModified = true; db.Entry(currentUser).Property(p => p.name).IsModified = true; db.Entry(currentUser).Property(p => p.surname).IsModified = true; db.Entry(currentUser).Property(p => p.country).IsModified = true; db.Entry(currentUser).Property(p => p.birth_date).IsModified = true; db.SaveChanges(); modelPanel.user = currentUser; modelPanel.info.type = 1; modelPanel.info.text = "Your data has been changed."; return View(modelPanel); } }
public static User isValidUserLogin(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); using (var database = new SuperAtletenEntities()) { var user = database.Users.Where(b => b.Email == email).FirstOrDefault(); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { return user; } } } return null; }
public bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; var user = context.Users.FirstOrDefault(u => u.Email == email); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { isValid = true; } } return isValid; }
public void Add(AddEditUserModel model) { var crypto = new SimpleCrypto.PBKDF2(); using (var uow = new UnitOfWork(new DataContext())) { var user = new User(); user.FirstName = model.FirstName; user.MiddleName = model.MiddleName; user.LastName = model.LastName; var encrypPass = crypto.Compute(model.Password); user.Password = encrypPass; user.PasswordSalt = crypto.Salt; user.Roles.Add(uow.Roles.Get(model.RoleID)); user.UserName = model.UserName; uow.Users.Add(user); uow.Complete(); } }
// POST: /Account/LogOff private bool IsValid(string UserName, string Pass) { var crypto = new SimpleCrypto.PBKDF2(); bool isvalid = false; var c = db.Users.FirstOrDefault(m => m.UserName == UserName); if (c != null) { Session["UserName"] = c.UserName; if (c.Pass == (crypto.Compute(Pass, c.PassSalt))) { isvalid = true; } } return(isvalid); }
public User CreateUser(string email, string password) { User user = null; if (context.Users.Where(u => u.email == email).FirstOrDefault() == null) { user = new User() { email = email, password = password, PasswordSalt = password }; var crypto = new SimpleCrypto.PBKDF2(); user.password = crypto.Compute(user.password); user.PasswordSalt = crypto.Salt; user.registeredDate = DateTime.Now; context.Users.Add(user); context.SaveChanges(); } return(user); }
private bool CheckPassword(string password) { var crypto = new SimpleCrypto.PBKDF2(); bool IsMatch = false; using (var db = new ecm.Models.ecmEntities2()) { string email = (string)Session["username"]; var user = db.users.FirstOrDefault(u => u.Email == email); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { IsMatch = true; } } } return(IsMatch); }
public Boolean isValid(string email, string password) { bool isValid = false; var crypto = new SimpleCrypto.PBKDF2(); using (var _db = new JaverianaReservasContext()) { var user = _db.usuarios.FirstOrDefault(u => u.email == email); if (user != null) { if (user.password == crypto.Compute(password, user.passwordSalt)) isValid = true; } } return isValid; }
public ActionResult Registration([Bind(Include = "Email,Password,User_Id,NickName,FullName,City,Gender_Id")] LesioBlog2_Repo.Models.User user) { //checking if email and nickname taken if (IsEmailUsernameTaken(user.Email, user.NickName)) { if (ModelState.IsValid) //password and email form checking { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); user.Password = encrpPass; user.PasswordSalt = crypto.Salt; //getting unique userID, checking with the database and repeating if userID selected //by random was not unique at all XD #region //userID var rnd = new Random(); user.User_Id = rnd.Next(); var matchingUser = _user.FindUserByID(user.User_Id); while (matchingUser != null) { user.User_Id = rnd.Next(); matchingUser = _user.FindUserByID(user.User_Id); } //default values: user.Role_Id = 2; //default user.Active = true; //deafult end #endregion _user.Add(user); _user.SaveChanges(); return(RedirectToAction("LogIn", "User")); } else { ModelState.AddModelError("", "Regiser data is incorrect"); } } else { ModelState.AddModelError("", "Email/Username taken, change it please"); } return(View(user)); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Clave); user.Clave = encrpPass; user.ClaveSalt = crypto.Salt; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.UserTypeId = new SelectList(db.Usertype, "usertypeid", "description", user.UserTypeId); return View(user); }
private bool isValid(string username, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; using (var db = new db_esosEntities()) { var user = db.users.FirstOrDefault(u => u.username == username); if (user != null) { if (user.user_password == crypto.Compute(password, user.user_passwordsalt)) { isValid = true; } } } return(isValid); }
public ActionResult Register(User user, Register reg) { string a = ""; string b = ""; if (ModelState.IsValid) { var crypto = new SimpleCrypto.PBKDF2(); var encrpass = crypto.Compute(reg.password); user.password = encrpass; User user2 = null; user2 = repository.Users.Where(u => u.email == reg.email).FirstOrDefault(); if (user2 == null) { user.passwordSalt = crypto.Salt; user.merchantLicense = false; user.tradeLicense = false; user.userGroupID = 1; user.email = reg.email; user.companyName = reg.companyName; user.contactPerson = reg.contactPerson; user.address = reg.address; user.juridicalAddress = reg.juridicalAddress; user.post = reg.post; user.phoneNumber = reg.phoneNumber; user.approved = false; repository.SaveUser(user); ModelState.Clear(); a = "Login"; b = "Account"; RedirectToAction(a, b); } else { ViewBag.Message = "Користувач уже існує!"; } } else { ViewBag.Message = "Невірні дані!"; } return View(); ; }
public bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new ApplicationDbContext()) { var user = db.Registeration.Where(u => u.Email == email).FirstOrDefault(); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { IsValid = true; } } } return(IsValid); }
public ActionResult Register(Project.Models.UserModel user) { if (ModelState.IsValid) { using (var db = new MainDbEntities()) { var crypto = new SimpleCrypto.PBKDF2(); var encryptedPass = crypto.Compute(user.Password); var sysuser = db.SystemUsers.Create(); sysuser.email = user.Email; sysuser.username = user.Username; sysuser.password = encryptedPass; sysuser.password = crypto.Salt; sysuser.Id = Guid.NewGuid(); db.SystemUsers.Add(sysuser); db.SaveChanges } } return(View()); }
private bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; using (var ctx = new StoresEntities()) { var user = ctx.Users.FirstOrDefault(u => u.Email.Equals(email)); if (user != null) { if (user.Password.Equals(crypto.Compute(password, user.PasswordSalt))) { isValid = true; } } } return(isValid); }
internal static User AuthenticateUser(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); using (var db = new Models.HacForoContainer()) { User user = db.UserSet.Include(u => u.Threads) .Include(u => u.UserThreadPoints) .FirstOrDefault(u => u.Email == email); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { return(user); } } } throw new UnauthorizedAccessException("The login data is invalid"); }
public bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new FlightsBookingsDBEntities()) { // retrieve the user according to the email entered var user = db.UsersTbls.FirstOrDefault(u => u.Email == email); if (user != null) { // and the password is the same as what enterd if (user.Password == crypto.Compute(password, user.Password_Salt)) { IsValid = true; } } } return(IsValid); }
private bool isValid(String email, String password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; using (var db = new UpravljanjeRecepturamaBaza()) { var osoba = db.Osoba.FirstOrDefault(o => o.Email == email); if (osoba != null) { if (osoba.Lozinka == crypto.Compute(password, osoba.Salt)) { isValid = true; } } } return(isValid); }
public static bool changePassword(int userid,string Newpassword,string passwordSalt,string Oldpassword) { using (var database = new SuperAtletenEntities()) { var user = database.Users.Where(b => b.Id == userid).FirstOrDefault(); if (user != null) { var crypto = new SimpleCrypto.PBKDF2(); if(user.Password == crypto.Compute(Oldpassword, user.PasswordSalt)) { user.Password = Newpassword; user.PasswordSalt = passwordSalt; database.SaveChanges(); return true; } } } return false; }
private bool IsValid(string email, string password) { var Cryptro = new SimpleCrypto.PBKDF2(); bool isValid = false; using (var db = new DBCon()) { var user = db.Users.FirstOrDefault(u => u.Email == email); if (user != null) { if (user.Password == Cryptro.Compute(password, user.PasswardSalt)) { isValid = true; } } } return(isValid); }
private bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new ecm.Models.ecmEntities2()) { var user = db.users.FirstOrDefault(u => u.Email == email); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { IsValid = true; flag = true; Uid = user.UserId; } } } return(IsValid); }
public ActionResult Register(Models.Registration user) { try { if (ModelState.IsValid) { using (var db = new Context()) { var crypto = new SimpleCrypto.PBKDF2(); var encrypPass = crypto.Compute(user.Password); var newUser = db.Registrations.Create(); newUser.Email = user.Email; newUser.Password = encrypPass; newUser.PasswordSalt = crypto.Salt; db.Registrations.Add(newUser); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Data is not correct"); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } return(View()); }
public IActionResult UpdateUser(UpdateUserModel user) // Updates room info { try { //only execute if form is valid if (ModelState.IsValid) { //create a crypto so the password can be stored savely var crypto = new SimpleCrypto.PBKDF2(); var encrypass = crypto.Compute(user.Passwordd); using (MySqlConnection conn = new MySqlConnection()) { conn.ConnectionString = "Server=drakonit.nl;Database=timbrrf252_roomreserve;Uid=timbrrf252_ictlab;Password=ictlabhro;SslMode=none"; conn.Open(); //enter the updated data into the database with this query String sql = "UPDATE user SET user_name = '" + user.Namee + "', user_password = '******', password_salt = '" + crypto.Salt + "' WHERE user_id = " + HomeController.UserId + ";"; MySqlCommand command = new MySqlCommand(sql, conn); command.ExecuteNonQuery(); conn.Close(); TempData["ModifiedUserDataSaved"] = "true"; return(RedirectToAction("Index", "Groups", HomeController.UserId)); } } else { //if the form is not filled in correctly show this to the user ModelState.AddModelError("", "Error while trying to update your credentials, try again"); TempData["ModifiedUserDataSaved"] = "false"; return(RedirectToAction("Index", "Groups", HomeController.UserId)); } } catch (Exception e) { //if error happen catch it Debug.WriteLine("Updateroom Exception: {0}", e); return(RedirectToAction("Error", "Home")); throw; } }
private bool IsValid(string login, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; using (var db = new DBminiLibrary()) { var user = db.tabUser.FirstOrDefault(u => u.Login == login); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { isValid = true; } } } return(isValid); }
public ActionResult Reset(string username, string password1, string password2) { DBModelEntities db = new MvcAdminTemplate.Models.DBModelEntities(); var user = db.Accounts.FirstOrDefault(u => u.Username == username); if (user != null && password1 == password2) { var crypto = new SimpleCrypto.PBKDF2(); var hashedPass = crypto.Compute(password1); // Hashes user password user.Password = hashedPass; user.PasswordSalt = crypto.Salt; db.SaveChanges(); return(RedirectToAction("Reset", "Account")); } else { ModelState.AddModelError("", "Data is incorrect"); return(View()); } }
private bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; using (var _db = new VLN2_2016_H42Entities()) { var user = _db.SystemUsers.FirstOrDefault(u => u.Username == email); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { isValid = true; } } } return(isValid); }
public void InsertPatient(PatientLogin patientlogin) { var crypto = new SimpleCrypto.PBKDF2(); var encrypPass = crypto.Compute(patientlogin.Password); patientlogin.Password = encrypPass; patientlogin.ConfirmPassword = encrypPass; patientlogin.PasswordSalt = crypto.Salt; patientlogin.FirstName = patientlogin.FirstName; patientlogin.LastName = patientlogin.LastName; patientlogin.EmailID = patientlogin.EmailID; patientlogin.IslockedOut = false; patientlogin.InactiveFlag = "N"; patientlogin.CreatedByID = 1; // for now we add 1 later we change patientlogin.CreatedDate = DateTime.Now; patientlogin.ModifiedByID = 1; // for now we add 1 later we change patientlogin.ModifiedDate = DateTime.Now; patientlogin.UserPhone = patientlogin.UserPhone; DBcontext.patientlogins.Add(patientlogin); }
private bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; using (var db = new mainDBContext()) { var user = db.SystemUsers.FirstOrDefault(u => u.Email == email); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { if (user.isActive) { isValid = true; } } } } return(isValid); }
public ActionResult Register(Project.Models.UserModel user) { if (ModelState.IsValid) { using (var db = new MainDbEntities()) { var crypto = new SimpleCrypto.PBKDF2(); var encryptedPass = crypto.Compute(user.Password); var sysuser = db.SystemUsers.Create(); sysuser.email = user.Email; sysuser.username = user.Username; sysuser.password = encryptedPass; sysuser.password = crypto.Salt; sysuser.Id = Guid.NewGuid(); db.SystemUsers.Add(sysuser); db.SaveChanges } } return View(); }
private void LoginButton_Click(object sender, EventArgs e) { ProjectManagementDatabaseClassesDataContext db = new ProjectManagementDatabaseClassesDataContext(); var crypto = new SimpleCrypto.PBKDF2(); string password = passwordTextBox.Text; string userName = userNameTextBox.Text; var result = db.getCurrentUser(userName); string salt = ""; string userType = ""; if (result != null) { foreach (var sResult in result) { salt = sResult.PasswordSalt; userType = sResult.UserType; Console.WriteLine("UserType: " + userType); } string hashedPassword = crypto.Compute(password, salt); int valid = con.tryLogin(userName, hashedPassword, userType); if (valid == 1) { this.Hide(); } else { Console.WriteLine("Wrong username or password"); } } }
// Ao clicar no butao de resposta, checa se a resposta está valida private void AnswerButton_Click(object sender, RoutedEventArgs e) { var crypto = new SimpleCrypto.PBKDF2(); String resposta = Answer.Text; if (user[0].resposta == crypto.Compute(resposta, user[0].respostasalt)) { NovaSenhaLabel.Visibility = Visibility.Visible; ChangeInterface(NewPassword, ChangeButton, IncorrectAnswer); AnswerButton.IsEnabled = false; AnswerButton.IsDefault = false; ChangeButton.IsDefault = true; } else { IncorrectAnswer.Visibility = Visibility.Visible; Answer.Text = ""; } }
public ActionResult Login(Login l, string ReturnUrl = "") { var crypto = new SimpleCrypto.PBKDF2(); var user = repository.Users.Where(a => a.email.Equals(l.email)).FirstOrDefault(); if (user != null) { user.password = crypto.Compute(l.password, user.passwordSalt); FormsAuthentication.SetAuthCookie(user.contactPerson, l.RememberMe); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("MyProfile", "Home")); } } ModelState.Remove("Password"); return(View()); }
public void Add(UserModel model) { if (model.Password != model.ReTypePassword) { throw new ApplicationException("Password does not match!"); } var crypto = new SimpleCrypto.PBKDF2(); using (var uow = new UnitOfWork(new DataContext())) { var user = new User(); var encrypPass = crypto.Compute(model.Password); user.FirstName = ""; user.MiddleName = ""; user.LastName = ""; user.UserName = model.UserName; user.Password = encrypPass; user.PasswordSalt = crypto.Salt; uow.Users.Add(user); uow.Complete(); } }
public ActionResult Register(Models.Employee employee) { try { if (ModelState.IsValid) { using (var db = new MvcApplication1.Models.RegistrationEntities()) { setId(); var crypto = new SimpleCrypto.PBKDF2(); var encryPass = crypto.Compute(employee.Password); var newUser = db.Employees.Create(); newUser.EmployeeID = this.id; newUser.FirstName = employee.FirstName; newUser.LastName = employee.LastName; newUser.Email = employee.Email; newUser.UserType = employee.UserType; newUser.Password = encryPass; newUser.PasswordSalt = crypto.Salt; newUser.CreatedDate = DateTime.Now; newUser.IPAddress = "Not Available"; db.Employees.Add(newUser); db.SaveChanges(); return(RedirectToAction("Login", "Registration")); } } else { ModelState.AddModelError("", "Data is not correct"); } } catch (DbUpdateException e) { } catch (DbEntityValidationException e) { } return(View(employee)); }
private void button1_Click_1(object sender, EventArgs e) { String pnr = textBox1.Text; String forename = textBox2.Text; String surname = textBox3.Text; String username = textBox4.Text; String password = textBox5.Text; String role = textBox6.Text; double num; bool isPnrNum = double.TryParse(pnr, out num); if (isPnrNum && !pnr.Equals("") && !forename.Equals("") && !surname.Equals("") && !password.Equals("") && !role.Equals("")) { var crypto = new SimpleCrypto.PBKDF2(); // string userName = con.getUserNameWithPnr(a); int pnrI = Convert.ToInt32(pnr); string passwordSalt = con.getCurrentUser(this.userId); string hashedPassword = crypto.Compute(password, passwordSalt); con.editProjectMember(pnrI, forename, surname, username, hashedPassword, role); mv.projectMemberDataGridView.DataSource = con.fillProjectMember(); this.Close(); } else { MessageBox.Show("Make sure everything is typed correctly"); } }
public ActionResult Register(TB_USER model) { if (ModelState.IsValid) { using (var db = new Entities()) { var user = db.TB_USER.FirstOrDefault(u => u.LOGIN == model.LOGIN); if (user == null) { var crypt = new SimpleCrypto.PBKDF2(); var encrypts = crypt.Compute(model.PASSWD); var vUser = db.TB_USER.Create(); vUser.LOGIN = model.LOGIN; vUser.PASSWD = encrypts; vUser.PASSWSALT = crypt.Salt; vUser.USER_NAME = model.USER_NAME; db.TB_USER.Add(vUser); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", String.Format("Unable to create local account. An account with the name \"{0}\" may already exist.", model.LOGIN)); } } } else { ModelState.AddModelError("", "Dados incorretos"); } return(View());//model); }
private bool IsValid(string email, string password) { try { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new UnitBookingDataContext()) { //Retrieve the first user with the email provided var user = db.Users.FirstOrDefault(u => u.Email == email); //If the user exists check if the password provided matches the store password after hashing if (user != null) { // Store the user temporarily in the context for this request. System.Web.HttpContext.Current.Items.Add("User", user); if (user.Password == crypto.Compute(password, user.PasswordSalt)) { //If the credentials provided are correct return true indicating the login was valid IsValid = true; } } else { //If the credentials were invalid return false indicating the credentials were invalid IsValid = false; } } return(IsValid); } catch (Exception e) { return(false); //Log error } }
public ActionResult Registrazione(UtenteCreateModel utente) { if (ModelState.IsValid) { using (DatabaseContext db = new DatabaseContext()) { var crypto = new SimpleCrypto.PBKDF2(); string encPassword = crypto.Compute(utente.Password); Utente nuovoUtente = db.Utenti.Create(); nuovoUtente.Email = utente.Email; nuovoUtente.Password = encPassword; nuovoUtente.PasswordSalt = crypto.Salt; nuovoUtente.UserName = utente.UserName; nuovoUtente.UserID = Guid.NewGuid(); db.Utenti.Add(nuovoUtente); db.SaveChanges(); } return(RedirectToAction("Index", "Home")); } return(View(utente)); }
public bool AddUser(UserModel user) { if(context.Users.FirstOrDefault(email => email.Email.Equals(user.Email)) == null) { var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(user.Password); User userToSave = context.Users.Create(); userToSave.Email = user.Email; userToSave.Password = encrPass; userToSave.PasswordSalt = crypto.Salt; userToSave.UserId = Guid.NewGuid(); context.Users.Add(userToSave); context.SaveChanges(); return true; } return false; }
public ActionResult LostPassword(LostPasswordModel LostPassword) { if (!ModelState.IsValid) { return View(); } var user = RegisterRepository.CheckIfEmailExists(LostPassword.EmailAdress); if (user == null) { ModelState.AddModelError("EmailDoesNotExist", "Emailadressen finns inte registrerad"); return View(); } //generates a new random password string newPassword = Membership.GeneratePassword(7, 4); //enrcrypts the new password var crypto = new SimpleCrypto.PBKDF2(); var encryptedPassword = crypto.Compute(newPassword); user.Password = encryptedPassword; user.PasswordSalt = crypto.Salt; UserRepository.UpdatePassword(user); //Sets the subject and the body for the confirmation mail string body = "Hej! <br /> Här kommer ditt nya autogenererade lösenord använd det för att logga in och " + "byta till ett nytt eget lösenord , Detta hittar du under inställningar/byt lösenord <br /><hr />" + "E-mail : <b> " + user.Email + "</b><br/>Ditt nya lösenord : <b>" + newPassword + "</b>" + "<br /><hr/>" + "Mvh SuperAtleten<br/> www.SuperAtleten.se <br/> [email protected]"; string subject = "Här kommer ditt nya lösenord"; //Sends the confirmation mail MailSender.sendMail(subject,body,user.Email); TempData["Message"] = "Dina användaruppgifter har skickats"; return RedirectToAction("Index","Home"); }
public static bool IsValid(string _rut, string _password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; try { using (var ctx = new Database.DB_InspeccionesEntities()) { var user = ctx.Usuario.FirstOrDefault(u => u.Rut == _rut); if (user != null) { string passCrypted = crypto.Compute(_password, user.PasswordSalt); if (user.Password == passCrypted) { isValid = true; } } } return isValid; } catch(Exception) { return isValid; } }
public ActionResult Registration(Models.UserModel user) { if (ModelState.IsValid) { using (var db = new mainDBContext()) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); var sysUser = db.SystemUsers.Create(); sysUser.Email = user.Email; sysUser.Password = encrpPass; sysUser.PasswordSalt = crypto.Salt; sysUser.UserId = Guid.NewGuid(); //can be done here or in DB one more change. last change sysUser.isActive = true; db.SystemUsers.Add(sysUser); db.SaveChanges(); return RedirectToAction("Index", "Home"); } } return View(user); }
public ActionResult Register(Login user) { if (ModelState.IsValid) { using (var db = new JaverianaReservasContext()) { var crypto = new SimpleCrypto.PBKDF2(); var userDB = db.usuarios.Create(); userDB.email = user.userName; userDB.password = crypto.Compute(user.password); userDB.passwordSalt = crypto.Salt; userDB.id = Guid.NewGuid(); db.usuarios.Add(userDB); db.SaveChanges(); return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "Error al registrar al usuario"); } return View(user); }