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 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 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 Registration(Mooshak2.ViewModels.UserModel user) { if (ModelState.IsValid) { using (var _db = new VLN2_2016_H42Entities()) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); var sysUser = _db.SystemUsers.Create(); sysUser.Username = user.Username; sysUser.Password = encrpPass; sysUser.PasswordSalt = crypto.Salt; sysUser.UserId = Guid.NewGuid(); _db.SystemUsers.Add(sysUser); _db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Login Data is incorret."); } return(View()); }
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 Registration(Models.UserModel user) { if (ModelState.IsValid) { using (var db = new MyMainDbEntities()) { var crypto = new SimpleCrypto.PBKDF2(); var encrypPass = crypto.Compute(user.Password); var sysUser = db.SystemUsers.Create(); sysUser.Email = user.Email; sysUser.Password = encrypPass; sysUser.PasswordSalt = crypto.Salt; sysUser.UserId = Guid.NewGuid(); db.SystemUsers.Add(sysUser); db.SaveChanges(); FormsAuthentication.SetAuthCookie(user.Email, false); return(RedirectToAction("Index", "User")); } } else { ModelState.AddModelError("", "Login credentials are incorrect."); } return(View(user)); }
private bool IsValid(string usuario, string clave) { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; var user = db.User.FirstOrDefault(u => u.Usuario == usuario); if (user != null) { var userType = db.Usertype.FirstOrDefault(u => user.UserTypeId == u.usertypeid); if (userType.description != "Deshabilitado") { var cry = crypto.Compute(clave, user.ClaveSalt); if (user.Clave == cry) { IsValid = true; UserLogsController.GuardarLogInLog(user); } } else { ModelState.AddModelError("", "Usuario deshabilitado"); } } return(IsValid); }
public ActionResult Details([Bind(Include = "UserId, Username, Password")] User user, string newPassword, string newConfirmPassword) { User newChange = db.User.Find(user.UserId); if (!isValid(user.Username, user.Password, false)) { ModelState.AddModelError("", "The old password doesn'\t match. Try again"); return(View(newChange)); } if (newPassword != newConfirmPassword || newPassword.Length < 6) { ModelState.AddModelError("", "The new password doesn'\t match or is too short. Try again"); return(View(newChange)); } var crypto = new SimpleCrypto.PBKDF2(); var encryptPass = crypto.Compute(newPassword); newChange.Password = encryptPass; newChange.PasswordSalt = crypto.Salt; db.Entry(newChange).State = EntityState.Modified; db.SaveChanges(); FormsAuthentication.SignOut(); TempData["changePass"] = "******"; return(RedirectToAction("Index", "Home")); }
public ActionResult Registration(CommerceIdeaBank.Models.User user) { if (ModelState.IsValid) { using (var db = new MainDBEntities()) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); var sysUser = db.Users.Create(); sysUser.Username = user.Username; sysUser.Email = user.Email; sysUser.Password = encrpPass; sysUser.PasswordSalt = crypto.Salt; sysUser.UserRole = 1; sysUser.IsActive = true; db.Users.Add(sysUser); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } return(View(user)); }
public ActionResult Registration(User user) { if (ModelState.IsValid) { var useridentico = db.User.FirstOrDefault(u => u.Usuario == user.Usuario); if (useridentico == null) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Clave); user.Clave = encrpPass; user.ClaveSalt = crypto.Salt; db.User.Add(user); db.SaveChanges(); return(RedirectToAction("Index", "Users")); } else { ModelState.AddModelError("", String.Concat("Ya hay un usuario '", useridentico.Usuario, "'")); } } else { ModelState.AddModelError("", "Datos de login erroneos"); } ViewBag.UserTypeId = new SelectList(db.Usertype, "usertypeid", "description", user.UserTypeId); return(View(user)); }
public void LoginUser(string userName, string password) { var crypto = new SimpleCrypto.PBKDF2(); using (var uow = new UnitOfWork(new DataContext())) { User user = uow.Users.GetUser(userName); if (user != null) { if (user.Password != crypto.Compute(password, user.PasswordSalt)) { throw new ApplicationException("Invalid Password!"); } else { CurrentUser.UserID = user.UserID; CurrentUser.Name = user.UserName; CurrentUser.Roles = user.Roles.Select(x => x.Description).ToList(); user.IsOnline = true; uow.Users.Edit(user); uow.Complete(); } } else { throw new ApplicationException("Invalid User Name!"); } } }
/// <summary> /// Check valid User /// </summary> /// <param name="email"></param> /// <param name="password"></param> /// <returns></returns> public bool IsValid(string email, string password) { IEnumerable <APN_User> user = null; bool IsValid = false; using (var client = new HttpClient()) { client.BaseAddress = new Uri(String.Concat(baseUrl, "api/APN_User")); var responseTask = client.GetAsync("APN_User"); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <IList <APN_User> >(); readTask.Wait(); user = readTask.Result; var crypto = new SimpleCrypto.PBKDF2(); var logUser = user.FirstOrDefault(u => u.Email == email); if (logUser != null) { if (logUser.Password == crypto.Compute(password, logUser.PasswordSalt)) { IsValid = true; } } } } return(IsValid); }
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 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 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 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 ActionResult Register(UserModel user) { if (ModelState.IsValid) { using (var ctx = new StoresEntities()) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); var sysUser = ctx.Users.Create(); sysUser.Email = user.Email; sysUser.Password = encrpPass; sysUser.PasswordSalt = crypto.Salt; sysUser.UserId = Guid.NewGuid(); ctx.Users.Add(sysUser); sysUser.Roles.Add(ctx.Roles.FirstOrDefault(r => r.Name.Equals("member"))); ctx.SaveChanges(); return(RedirectToAction("Index", "User")); } } ViewBag.Title = "Email is already in use!"; return(View(user)); }
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); }
private bool IsValid(string usernam, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new paresetEntities()) { var user = db.Userinfoes.FirstOrDefault(u => u.username == usernam); if (user != null) { if (user.password == crypto.Compute(password, user.passwordsalt)) { return(true); } } int count = int.Parse(user.failurecount.ToString()); user.failurecount = count + 1; db.Entry(user).CurrentValues.SetValues(user); db.SaveChanges(); } return(IsValid); }
public ActionResult Register(tblUsers userModel) { using (DemirStoreDBEntities dbModel = new DemirStoreDBEntities()) { if (dbModel.tblUsers.Any(x => x.Email == userModel.Email)) { ViewBag.DuplicateMessage = "Bu e mail daha önceden alındı."; return(View("Register", userModel)); } else if (dbModel.tblUsers.Any(x => x.PhoneNumber == userModel.PhoneNumber)) { ViewBag.DuplicateMessage = "Bu telefon numarası daha önceden alındı."; return(View("Register", userModel)); } var crypto = new SimpleCrypto.PBKDF2(); string encryptedPswd = crypto.Compute(userModel.Pswd); userModel.Pswd = encryptedPswd; userModel.ConfirmPswd = encryptedPswd; userModel.PswdSalt = crypto.Salt; userModel.isVerified = false; dbModel.tblUsers.Add(userModel); dbModel.SaveChanges(); return(View("Login")); } }
private bool IsValidAdmin(string usernam, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new paresetEntities()) { //var user = from u in db.Userinfoes // where u.username == usernam // select u.password; //List<string> lstResult = (from table in db.Userinfoes // where table.username == usernam // select table.password).ToList(); var user = db.Admininfoes.FirstOrDefault(u => u.adminname == usernam); //if (lstResult.Count != 0) //{ // string dtStatus = lstResult[0]; if (user != null) { if (user.adminpass == password) { IsValid = true; } } // } } return(IsValid); }
public ActionResult Create(Person pid) { if (ModelState.IsValid) { var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(pid.Password); var sysUser = db.People.Create(); sysUser.Firstname = pid.Firstname; sysUser.Lastname = pid.Lastname; sysUser.Address1 = pid.Address1; sysUser.Address2 = pid.Address2; sysUser.City = pid.City; sysUser.St = pid.St; sysUser.Zip = pid.Zip; sysUser.Username = pid.Username; sysUser.Phonenumber1 = pid.Phonenumber1; sysUser.Email = pid.Email; pid.Password = encrPass; pid.PasswordSalt = crypto.Salt; // sysUser.PersonID = Guid.NewGuid(); db.People.Add(pid); db.SaveChanges(); ModelState.Clear(); pid = null; ViewBag.Message = "Successfully done"; } return(View(pid)); }
public User ValidateUser(Models.LoginModel loginModel) { try { var crypto = new SimpleCrypto.PBKDF2(); User user = userrepo.Find(model => model.LoginID == loginModel.LoginID); if (user != null) { if (user.Password == crypto.Compute(loginModel.Password, user.PasswordSalt)) { return(user); } else { return(null); } } return(user); } catch (Exception e) { throw e; } }
/// <summary> /// Changes the password. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="newPassword">The new password.</param> /// <returns></returns> public bool ChangePassword(string userName, string newPassword) { //if (IsValidUsernameAndPassword(userName, currentpassword)) //{ try { var crypto = new SimpleCrypto.PBKDF2(); var hashedPassword = crypto.Compute(newPassword); var salt = crypto.Salt; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = $"UPDATE Players SET Password = '******', PasswordSalt = '{salt}' WHERE NickName = '{userName}'"; command.ExecuteNonQuery(); return(true); } } } catch { // do some logging return(false); } //} //return false; }
public ActionResult Register(Models.UserModel User) { if (ModelState.IsValid) { using (var db = new mainDBEntities()) { 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(); return(RedirectToAction("Index", "Home")); } } return(View(User)); }
public ActionResult Create(FormCollection collection) { var us = db.Registrations.Where(c => c.Email == User.Identity.Name).FirstOrDefault(); try { if (us.Role == "Admin") { Registration user = new Registration(); user.Password = Convert.ToString(collection["Password"]); user.UserName = Convert.ToString(collection["UserName"]); user.Role = Convert.ToString(collection["Role"]); user.Email = Convert.ToString(collection["Email"]); var crypto = new SimpleCrypto.PBKDF2(); var encrypPass = crypto.Compute(user.Password); //var newUser = db.Registrations.Create(); user.Password = encrypPass; user.PasswordSalt = crypto.Salt; db.Registrations.Add(user); db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
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 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(); }
/* This method is used for authentication in login and check if there * exist user in the base */ private bool isValid(string username, string password, bool forExist) { var crypto = new SimpleCrypto.PBKDF2(); bool validation = false; using (var db = new Blog.Models.BlogDataEntities()) { var user = db.User.FirstOrDefault(u => u.Username == username); if (user != null) { if (forExist == true) { return(true); } if (user.Password == crypto.Compute(password, user.PasswordSalt)) { validation = true; } } } return(validation); }
public bool IsValidUsernameAndPassword(string userName, string password) { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = $"SELECT Password, PasswordSalt FROM Players WHERE NickName = '{userName}'"; using (var reader = command.ExecuteReader()) { if (reader.Read()) { var crypto = new SimpleCrypto.PBKDF2(); var salt = reader.GetString(reader.GetOrdinal("PasswordSalt")); var hash = reader.GetString(reader.GetOrdinal("Password")); var hashedPassword = crypto.Compute(password, salt); return(crypto.Compare(hash, hashedPassword)); } return(false); } } } }
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(); }
private bool IsValid(string username, string password, out string AF) { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; //using (var db = new SeniorMVC.Models.Final_Senior_DBEntities1()) //{ // var user = db.Users.FirstOrDefault(u => u.Username == username); var prox = new NashClient.NsashServicesClient(); UserModel usermodel = new UserModel(); usermodel.Username = username; AF = "N"; var user = prox.SignIn(usermodel); if (user.AdminFlag == 'Y') { AF = "Y"; } if (user != null) { string enc = crypto.Compute(password, user.PasswordSalt); if (user.Password.Trim() == enc) { IsValid = true; } } return(IsValid); }
public void CreateUser(User user) { if (_userRepository.GetUser(null, user.UserName) != null) { throw new Exception($"An user with the name {user.UserName} allready exist"); } if (_userRepository.GetUser(null, null, user.Email) != null) { throw new Exception($"An user with the email {user.Email} allready exist"); } if (user.Roles == null || user.Roles.Count == 0) { throw new Exception($"The user with Id : {user.Id} have no role"); } user.IsActive = true; // encrypte password and get salt var crypto = new SimpleCrypto.PBKDF2(); user.Password = crypto.Compute(user.Password); user.PasswordSalt = crypto.Salt; _userRepository.Insert(user); }
//Login logic: Den tar emot data från en ajax post request och sen kollar om användaren finns i databasen //och om lösenordet stämmer, om allt stämmer sparas användaren e in Session kallad user. public ActionResult Login(FormCollection collection) { var crypto = new SimpleCrypto.PBKDF2(); Models.User u = new Models.User(); u.userName = collection["user"]; u.password = collection["password"]; Models.User loggedIn = u.checkUser(u); //kollar om anvädaren finns i databasen if (loggedIn != null) { if (loggedIn.password == u.password) //kollar om lösenordet stämmer { Session["user"] = loggedIn; return(Json(new { msg = "success" })); } else { ViewBag.WrongInfo = "Fel lösenord!"; return(Json(new { msg = "Fel lösenord" })); } } else { ViewBag.WrongInfo = "Fel info. Försök igen!"; return(Json(new { msg = "Fel info. Försök igen." })); } }
public void LoginUser(string userName, string password) { var crypto = new SimpleCrypto.PBKDF2(); using (var uow = new UnitOfWork(new DataContext())) { User user = uow.Users.GetUser(userName); if (user != null) { if (user.Password != crypto.Compute(password, user.PasswordSalt)) { throw new ApplicationException("Invalid Password!"); } else { CurrentUser.UserID = user.UserID; CurrentUser.UserName = user.UserName; } } else { throw new ApplicationException("Invalid User Name!"); } } }
protected void SubmitButton_Click(object sender, EventArgs e) { string passTemp = System.Web.Security.Membership.GeneratePassword(7, 2); try { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); conn.Open(); SqlCommand comando = new SqlCommand("", conn); comando.CommandText = "select email from Account where username = '******'"; SqlDataReader reader = comando.ExecuteReader(); reader.Read(); string email = (string)reader["email"]; var crypto = new SimpleCrypto.PBKDF2(); string encriptPass = crypto.Compute(passTemp); conn.Close(); conn.Open(); comando = new SqlCommand("", conn); comando.CommandText = "update Account set password='******', passwordSalt ='" + crypto.Salt + "' where username ='******'"; comando.ExecuteNonQuery(); conn.Close(); sendMail(email, passTemp); } catch (Exception ex) { ex.ToString(); Response.Redirect(Request.Url.ToString()); } Response.Redirect("Default.aspx"); }
public ActionResult Register(RegisterModel user) { // verify that the model being passed is valid if (ModelState.IsValid) { // encrypt user password using PBKDF2 encryption var crypto = new SimpleCrypto.PBKDF2(); var encryptedPw = crypto.Compute(user.Password); // create new record for Users table var newUser = db.Users.Create(); // define values for new User record newUser.Username = user.Username; newUser.Email = user.Email; newUser.Password = encryptedPw; // store encrypted password newUser.PasswordSalt = crypto.Salt; // store password salt // add new record to the table and save db.Users.Add(newUser); db.SaveChanges(); // once account created, redirect to /Account/Login return RedirectToAction("LogIn", "Account"); } else { // if model is invalid, throw error ModelState.AddModelError("", "Account creation failed."); } return View(user); }
public ActionResult UserAccount(User user) { var Cryptro = new SimpleCrypto.PBKDF2(); string User = this.User.Identity.Name.ToString(); using (var db = new DBCon()) { var _User = db.Users.FirstOrDefault(u => u.Email == User); if (user.Password == Cryptro.Compute(_User.Password, _User.PasswardSalt) || user.Password == _User.Password) { _User.FirstName = user.FirstName; _User.LastName = user.LastName; _User.Address = user.Address; db.SaveChanges(); } else { var Crypto = new SimpleCrypto.PBKDF2(); var EncPass = Crypto.Compute(user.Password); _User.Password = EncPass; _User.PasswardSalt = Crypto.Salt; _User.FirstName = user.FirstName; _User.LastName = user.LastName; _User.Address = user.Address; db.SaveChanges(); } return(RedirectToAction("Index", "Home", new { id = _User.IDUser })); } }
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 Registration(User user) { if (ModelState.IsValid) { using (var db = new DBCon()) { var Crypto = new SimpleCrypto.PBKDF2(); var EncPass = Crypto.Compute(user.Password); var User = db.Users.Create(); User.Email = user.Email; User.FirstName = user.FirstName; User.LastName = user.LastName; User.Password = EncPass; User.PasswardSalt = Crypto.Salt; User.Address = user.Address; db.Users.Add(User); db.SaveChanges(); FormsAuthentication.SetAuthCookie(user.Email, false); ViewData["userName"] = user.FirstName.ToString(); User Model = db.Users.FirstOrDefault(u => u.Email == user.Email); return(RedirectToAction("Index", "Home", new { id = Model.IDUser })); } } return(View()); }
public static UserAuth login(membership param) { using (conferenceadminContext contx = new conferenceadminContext()) { /*UserAuth user = (from g in contx.memberships join u in contx.users on g.membershipID equals u.membershipID where g.email == param.email && g.password.Equals(param.password) && g.deleted == false && u.deleted == false select new UserAuth { userID = u.userID, memberID = g.membershipID, password = g.password, email = g.email, userType = u.userTypeID }).FirstOrDefault(); */ //copy paste del query de maria, solo quite: && g.password.Equals(param.password) del where clause y anadi: passwordSalt = g.passwordSalt, al select UserAuth user = (from g in contx.memberships join u in contx.users on g.membershipID equals u.membershipID where g.email == param.email && g.deleted == false && u.deleted == false select new UserAuth { userID = u.userID, memberID = g.membershipID, password = g.password, email = g.email, userType = u.userTypeID }).FirstOrDefault(); if (user == null) { return null; } else { var crypto = new SimpleCrypto.PBKDF2(); if (Security.ValidateSHA1HashData(param.password, user.password)) // if( string.Equals(crypto.Compute(param.password, user.passwordSalt), user.password, StringComparison.Ordinal)) return user; else{ return null; } } } }
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()); }
[HttpPost] //After the user enters the information public ActionResult RegisterUser(Models.UserModel user) { if (ModelState.IsValid) { using (var db = new MailAppDBEntities()) { var Crypto = new SimpleCrypto.PBKDF2(); var encPass = Crypto.Compute(user.Password); var SysUser = db.Users.Create(); SysUser.Email = user.Email; SysUser.Password = encPass; SysUser.PasswordSalt = Crypto.Salt; SysUser.UserID = Guid.NewGuid(); SysUser.Name = user.Name; SysUser.LastName = user.LastName; SysUser.Genre = user.Genre; SysUser.BirthDay = user.BirthDay; db.Users.Add(SysUser); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Login Data is incorrect"); } 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; }
/// <summary> /// Redes sociais /// </summary> /// <param name="xEmail"></param> /// <param name="xSenha"></param> /// <returns></returns> public bool IsExist(string xUserName) { 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) { IsValid = true; } } return IsValid; }
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 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 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 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); }
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; }
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(); }
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"); }