Exemplo n.º 1
0
        protected void Register_Click(object sender, EventArgs e)
        {
            //get the captcha string
            string captchaString = CaptchaImg.ImageUrl.Substring(CaptchaImg.ImageUrl.Length - 6);

            //compare with the input
            if (captchaString != captchaInput.Text)
            {
                regError.Text = "Captcha verification failed!";
                return;
            }
            //reload the captcha image
            ImageClickEventArgs e1 = new ImageClickEventArgs(0, 0);

            CaptchaImg_Click(sender, e1);
            captchaInput.Text = "";

            //check if the password input fits all requirements
            if (password.Text.Length < 8 || password.Text.Length > 16 || !password.Text.Any(char.IsUpper))
            {
                pwdInvalid.Visible = true;
                return;
            }

            //check two passwords are same
            if (password.Text != passwordReenter.Text)
            {
                pwdError.Visible = true;
                return;
            }

            //to avoid html error
            string pwd = password.Text.Replace("&", "&amp;");

            //check if user name is legal
            Regex checkName = new Regex(@"^[a-zA-Z_ ]+$");

            if (!checkName.IsMatch(nameInput.Text))
            {
                userExist.Text    = "Invalid User Name!";
                userExist.Visible = true;
                return;
            }

            //check if the existance of the user name
            if (MemberExist.HasMember(nameInput.Text))
            {
                userExist.Visible = toLogin.Visible = true;
                return;
            }

            //wirte the user info to xml
            RecordMemberInfo(nameInput.Text, pwd);
            //redirect to the member page with the user name (auto log in)
            Response.Redirect("Member.aspx?name=" + nameInput.Text);
        }
Exemplo n.º 2
0
        protected void LogInBut_Click(object sender, EventArgs e)
        {
            //get the captcha string
            string captchaString = CaptchaImg.ImageUrl.Substring(CaptchaImg.ImageUrl.Length - 6);

            //compare with the input
            if (captchaString != captchaInput.Text)
            {
                LogInErr.Text = "Captcha verification failed!";
                return;
            }

            //reload the captcha image
            ImageClickEventArgs e1 = new ImageClickEventArgs(0, 0);

            CaptchaImg_Click(sender, e1);
            captchaInput.Text = "";

            //check the user name exists in the xml
            if (!MemberExist.HasMember(userName.Text))
            {
                LogInErr.Text = "User name not found!";
                return;
            }

            //check the password with the one stores in the xml
            if (GetPassword(userName.Text) != password.Text)
            {
                LogInErr.Text = "Password wrong!";
                return;
            }

            //if the user want to add the cookie
            if (Remember.Checked)
            {
                SetRememberMe(userName.Text, password.Text);
            }
            else
            {
                //will clear the cookie if the user does not check Remember Me box during this log in

                /*HttpCookie checkCookies = Request.Cookies["RememberMe"];
                 * if (checkCookies != null && checkCookies["Name"] != "")
                 * {
                 *  Response.Cookies.Remove("RememberMe");
                 *  checkCookies.Expires = DateTime.Now.AddDays(-10);
                 *  checkCookies.Value = null;
                 *  Response.SetCookie(checkCookies);
                 * }*/
            }
            //redirect to the member page with the user name
            Response.Redirect("Member.aspx?name=" + userName.Text + "&rem=" + Remember.Checked);
        }