Beispiel #1
0
        public ActionResult Create(UserProfile userProfile)
        {
            byte[] salt     = PasswordEncryption.GenerateSalt();
            var    password = Encoding.UTF8.GetBytes(userProfile.Password);

            var hashedPassword = PasswordEncryption.HashPasswordWithSalt(password, salt);

            userProfile.Password = Convert.ToBase64String(hashedPassword);


            if (userProfile.Image != null)
            {
                string fileName        = Path.GetFileNameWithoutExtension(userProfile.ImageFile.FileName);
                string extension       = Path.GetExtension(userProfile.ImageFile.FileName);
                string imageFolderPath = "~/Images/";

                fileName          = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                userProfile.Image = imageFolderPath + fileName;
                fileName          = Path.Combine(Server.MapPath(imageFolderPath), fileName);

                userProfile.ImageFile.SaveAs(fileName);
            }


            if (ModelState.IsValid)
            {
                db.UserProfile.Add(userProfile);
                db.SaveChanges();
                ModelState.Clear();

                return(RedirectToAction("Index"));
            }

            return(View(userProfile));
        }
Beispiel #2
0
        public ActionResult Edit(UserProfile userProfile)
        {
            byte[] salt     = PasswordEncryption.GenerateSalt();
            var    password = Encoding.UTF8.GetBytes(userProfile.Password);

            var hashedPassword = PasswordEncryption.HashPasswordWithSalt(password, salt);

            userProfile.Password = Convert.ToBase64String(hashedPassword);

            if (ModelState.IsValid)
            {
                db.Entry(userProfile).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(userProfile));
        }