Example #1
0
        public void UserFormView_InsertItem(WebshopClick.Model.BLL.User user)
        {
            //Checks if username already exists in the database
            TextBox userName = (TextBox)UserFormView.FindControl("Login");
            Service service = new Service();
            User checkUser = service.GetUserByLoginID(userName.Text);
            if (checkUser != null)
            {
                Session["Reg"] = true;
                PlaceHolderCheckFail.Visible = true;
                return;
            }

            //Salting password before hashing
            TextBox pswOriginal = (TextBox)UserFormView.FindControl("Password");
            pswOriginal.Text = pswOriginal.Text + userName.Text;
            TextBox pswConfirm = (TextBox)UserFormView.FindControl("ConfirmPassword");
            pswConfirm.Text = pswConfirm.Text + userName.Text;

            //Hashing of password
            string hash1 = PasswordHasher.Hash(pswOriginal.Text);
            string hash2 = PasswordHasher.Hash(pswConfirm.Text);
            if (ModelState.IsValid)
            {
                try
                {
                    user.Password = hash1;
                    service.UpdateUser(user);
                    FlashPlaceHolder.Visible = true;
                    isLoged();
                }
                catch (Exception)
                {
                    ModelState.AddModelError(String.Empty, "Fel inträffade då användare skulle läggas till.");
                }
            }
        }