Пример #1
0
        /// <summary>
        /// Event handler for signup button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_signup_Click(object sender, EventArgs e)
        {
            // clear all error labels
            lbl_username_error.Text   = "";
            lbl_pass_error.Text       = "";
            lbl_pass_cnfrm_error.Text = "";
            lbl_captcha_error.Text    = "";
            // check if username field is blank
            if (txt_username.Text == null || txt_username.Text == "")
            {
                lbl_username_error.Text = "Email is empty!";
                return;
            }
            // check if password is blank
            if (txt_pass.Text == null || txt_pass.Text == "")
            {
                lbl_pass_error.Text = "Password is empty!";
                return;
            }
            // check if passwords match
            if (!txt_pass.Text.Equals(txt_pass_cnfrm.Text))
            {
                lbl_pass_error.Text       = "Passwords do not match!";
                lbl_pass_cnfrm_error.Text = "Passwords do not match!";
                return;
            }
            // check if username is taken
            string[] usrNmChk = EncryptDecypt.readXml(txt_username.Text, false);
            if (usrNmChk != null && !usrNmChk[0].Equals("FILE NOT FOUND"))
            {
                // username was found in file
                lbl_username_error.Text = "Username taken, please choose again";
                txt_username.Text       = "";
                return;
            }
            // check captcha string
            if (!Session["generatedString"].Equals(txt_img_string.Text))
            {
                lbl_captcha_error.Text = "Incorrect verify string, try again.";
                return;
            }

            //no errors so sign member up
            signup();
        }
Пример #2
0
        /// <summary>
        /// Event handler for a login click.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_mber_login_Click(object sender, EventArgs e)
        {
            // check if the username has been set by the cookie logic.
            if (username == null)
            {
                username = txt_username.Text;
            }
            string password = txt_pass.Text;

            // clear errors
            lbl_username_error.Text = "";
            lbl_pass_error.Text     = "";
            // check if username is empty
            if (username == null || username == "")
            {
                lbl_username_error.Text = "username is empty!";
                return;
            }
            // check if password is empty
            if (password == null || password == "")
            {
                lbl_pass_error.Text = "Password is empty!";
                return;
            }
            //check if credentials are correct
            string[] passWrdChk = EncryptDecypt.readXml(username, chk_staff.Checked);
            if (passWrdChk == null || passWrdChk[0].Equals("FILE NOT FOUND"))
            {
                lbl_username_error.Text = "Username not found or incorrect, please try again";
                txt_username.Text       = "";
                return;
            }
            else
            {
                string[] encryptedPass  = passWrdChk[0].Split(',');
                byte[]   encryptedBytes = new byte[encryptedPass.Length];
                for (int i = 0; i < encryptedPass.Length; i++)
                {
                    encryptedBytes[i] = Convert.ToByte(encryptedPass[i]);
                }

                string[] strKey   = passWrdChk[1].Split(',');
                byte[]   keyBytes = new byte[strKey.Length];
                for (int i = 0; i < strKey.Length; i++)
                {
                    keyBytes[i] = Convert.ToByte(strKey[i]);
                }

                string[] strIV   = passWrdChk[2].Split(',');
                byte[]   ivBytes = new byte[strIV.Length];
                for (int i = 0; i < strIV.Length; i++)
                {
                    ivBytes[i] = Convert.ToByte(strIV[i]);
                }

                string decryptedPass = "";
                Aes    aesAlg;
                using (aesAlg = Aes.Create())
                {
                    decryptedPass = EncryptDecypt.DecryptStringFromBytes_Aes(encryptedBytes, keyBytes, ivBytes);
                }

                if (password.Equals(decryptedPass))
                {
                    if (chk_remember.Checked)
                    {
                        //create user cookie
                        Response.Cookies["authcookie"]["username"] = username;
                        Response.Cookies["authcookie"].Expires     = DateTime.Now.AddMonths(6);
                    }
                    //create user session
                    Session["username"] = username;

                    //staff session?
                    if (chk_staff.Checked)
                    {
                        Session["staff"] = true;
                    }
                    else
                    {
                        Session["staff"] = false;
                    }
                    //Access member page if everything worked
                    Response.Redirect("~/stockPage.aspx");
                }
                else
                {
                    lbl_pass_error.Text = "Incorrect password, please try again.";
                    txt_pass.Text       = "";
                }
            }
        }