public ActionResult Login(USERS user) { using (CinemaEntities db = new CinemaEntities()) { byte[] client_password = Encoding.Default.GetBytes(user.PASSWORD); //utworzenie skrotu od pobranego hasla (SHA_1) using (var sha1 = SHA1.Create()) { byte[] client_password_sha1 = sha1.ComputeHash(client_password); string s_client_password_sha1 = Encoding.Default.GetString(client_password_sha1); user.PASSWORD = s_client_password_sha1; } var usr = db.USERS.Where(u => u.USER_LOGIN == user.USER_LOGIN && u.PASSWORD == user.PASSWORD).FirstOrDefault(); if (usr != null) { Session["USER_LOGIN"] = usr.USER_LOGIN.ToString(); Session["USER_NAME"] = usr.NAME.ToString(); usr.LAST_LOGIN = DateTime.Now; db.Entry(usr).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("", "Home")); } else { ModelState.AddModelError("", "Dane logowania są niepoprawne!"); } } return(View()); }
public ActionResult Edit([Bind(Include = "Id,Title,ReleaseDate,Genre,ProducerId")] Movie movie) { if (ModelState.IsValid) { db.Entry(movie).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProducerId = new SelectList(db.Producer, "Id", "Name", movie.ProducerId); return(View(movie)); }
public ActionResult Edit(int id, Producer p) { try { // TODO: Add update logic here ce.Entry(p).State = System.Data.Entity.EntityState.Modified; ce.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult ChangePass(string[] pass) { if (Session["USER_LOGIN"] != null) { using (CinemaEntities db = new CinemaEntities()) { byte[] old_password = Encoding.Default.GetBytes(pass[0]); //utworzenie skrotu od pobranego hasla (SHA_1) using (var sha1 = SHA1.Create()) { byte[] old_password_sha1 = sha1.ComputeHash(old_password); string s_old_password_sha1 = Encoding.Default.GetString(old_password_sha1); string user_login = Session["USER_LOGIN"].ToString(); if (s_old_password_sha1 == db.USERS.Where(x => x.USER_LOGIN == user_login).Select(x => x.PASSWORD).FirstOrDefault().ToString()) { if (pass[1] == pass[2]) { //nowe hasla sa poprawne byte[] new_pass1 = Encoding.Default.GetBytes(pass[1]); byte[] new_pass1_sha1 = sha1.ComputeHash(new_pass1); //skrot sha_1 w byte string s_new_pass1_sha1 = Encoding.Default.GetString(new_pass1_sha1); var findUser = db.USERS.Where(u => u.USER_LOGIN == user_login).FirstOrDefault(); findUser.PASSWORD = s_new_pass1_sha1; db.Entry(findUser).State = EntityState.Modified; db.SaveChanges(); ModelState.AddModelError("", "Hasło zmieniono poprawnie!"); } else { ModelState.AddModelError("", "Podane hasła nie zgadzają się!"); } } //podano niepoprawne stare haslo else { ModelState.AddModelError("", "Podane stare hasło jest nieprawidłowe!"); } } return(View()); } } else { return(RedirectToAction("", "Home")); } }
public ActionResult Edit([Bind(Include = "USER_LOGIN,PASSWORD,NAME,SURNAME,E_MAIL,TELEPHONE,LAST_LOGIN")] USERS uSERS) { if (uSERS.NAME != "" && uSERS.SURNAME != "" && uSERS.E_MAIL != "" && uSERS.TELEPHONE != "") { using (CinemaEntities db = new CinemaEntities()) { string login = Session["USER_LOGIN"].ToString(); var findUser = db.USERS.Where(u => u.USER_LOGIN == login).FirstOrDefault(); findUser.NAME = uSERS.NAME; findUser.SURNAME = uSERS.SURNAME; findUser.E_MAIL = uSERS.E_MAIL; findUser.TELEPHONE = uSERS.TELEPHONE; db.Entry(findUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } return(View(uSERS)); }