Exemplo n.º 1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            DbLayer db = new DbLayer();

            String name  = tbRegName.Text;
            String email = tbRegEmail.Text;
            string pwd   = "";

            if (name.Length / 3 == 0)
            {
                pwd = SimpleHash.ComputeHash(tbRegPwd.Text, "SHA1", null);
            }
            else if (name.Length / 3 == 2)
            {
                pwd = SimpleHash.ComputeHash(tbRegPwd.Text, "SHA256", null);
            }
            else
            {
                pwd = SimpleHash.ComputeHash(tbRegPwd.Text, "SHA512", null);
            }

            String region = DropDownList1.Text;

            // Validation Password
            bool bCheckPwd = PasswordCheck.IsValidPassword(tbRegPwd.Text, 8, 4, true, true, true, true);

            if (!bCheckPwd)
            {
                string script = "alert(\"At least 8 characters, all strong conditions met (>= 8 chars with 1 or more UC letters, LC letters, digits & special chars)\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                                    "ServerControlScript", script, true);
                return;
            } //A1contact!

            // Validation UserID
            bool bCheckID = db.checkUserID(email);

            if (!bCheckID)
            {
                string script = "alert(\"The username already exists. Please use a different username.\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                                    "ServerControlScript", script, true);
                return;
            } //A1contact!

            int id = db.getMaxUser();

            db.saveUser(id, email, pwd, name, region);

            Response.Cookies["user"].Value   = email;
            Response.Cookies["user"].Expires = DateTime.Now.AddDays(3);
            Response.Redirect("Login.aspx");
        }
Exemplo n.º 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            DbLayer db = new DbLayer();

            // Validation Old Password
            bool bCheckPwdOld = PasswordCheck.IsValidPassword(tbOldPwd.Text, 8, 4, true, true, true, true);

            if (!bCheckPwdOld)
            {
                string script = "alert(\"At least 8 characters, all strong conditions met (>= 8 chars with 1 or more UC letters, LC letters, digits & special chars)\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                                    "ServerControlScript", script, true);
                return;
            } //A1contact!

            string passwordHashSha256 = db.getUserPwd(tbEmail.Text);

            if (passwordHashSha256 == null)
            {
                string script = "alert(\"Try Again!\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                                    "ServerControlScript", script, true);
                return;
            }

            // Hashing Password
            string pwdOldCheck = "";

            if (Request.Cookies["user"].Value.Length / 3 == 0)
            {
                pwdOldCheck = SimpleHash.VerifyHash(tbOldPwd.Text, "SHA2", passwordHashSha256).ToString();
            }
            else if (Request.Cookies["user"].Value.Length / 3 == 2)
            {
                pwdOldCheck = SimpleHash.VerifyHash(tbOldPwd.Text, "SHA256", passwordHashSha256).ToString();
            }
            else
            {
                pwdOldCheck = SimpleHash.VerifyHash(tbOldPwd.Text, "SHA512", passwordHashSha256).ToString();
            }

            if (pwdOldCheck.Equals("False"))
            {
                string script = "alert(\"Input Correct Password!\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                                    "ServerControlScript", script, true);
                return;
            }

            // Validation Password
            bool bCheckPwd = PasswordCheck.IsValidPassword(tbRegPwd.Text, 8, 4, true, true, true, true);

            if (!bCheckPwd)
            {
                string script = "alert(\"At least 8 characters, all strong conditions met (>= 8 chars with 1 or more UC letters, LC letters, digits & special chars)\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                                    "ServerControlScript", script, true);
                return;
            } //A1contact!

            string pwd = "";

            if (tbUserName.Text.Length / 3 == 0)
            {
                pwd = SimpleHash.ComputeHash(tbRegPwd.Text, "SHA1", null);
            }
            else if (tbUserName.Text.Length / 3 == 2)
            {
                pwd = SimpleHash.ComputeHash(tbRegPwd.Text, "SHA256", null);
            }
            else
            {
                pwd = SimpleHash.ComputeHash(tbRegPwd.Text, "SHA512", null);
            }

            //int id = db.getMaxUser();
            db.UpdateUserPwd(userID, pwd);
            Response.Redirect("Login.aspx");
        }