如何修复此注册码 [英] How do I fix this register code

查看:77
本文介绍了如何修复此注册码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注册表格并且正在进行检查,但它仍然创建了帐户,有人可以帮我纠正这个吗?





I have a register form and its doing the checks right but its still created the account can someone help me correct this?


string sha1HashStr = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
               string pattern = null;
               pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";

               if (!Regex.IsMatch(txtemail.Text, pattern))
               {
                 MessageBox.Show("Not a valid Email address ");
               }


               string[] stringArray = { "admin", "owner", "Owner", "Admin","Mod","mod","M0d","m0d" };
               foreach (string x in stringArray)
               {
                   if (x.Equals(username))
                   {
                       // stringToCheck = stringToCheck.Replace(x, "****");
                       MessageBox.Show("That username is not allowed","Username not allowed");
                   }


               }
              adapter = new MySqlDataAdapter("SELECT `username` FROM `users` WHERE `username` ='"+ txtuser.Text +"'", mcon);

                           adapter.Fill(table);

               if (table.Rows.Count >= 1)
               {
                   MessageBox.Show("Username Already Exists. Please Try Again","Username Exists");
                   return;
               }

               if (username == "" || username == string.Empty)
               {
                   MessageBox.Show("Please enter an username","Error");
                   this.txtuser.Focus();



               }
               else if (password == "" || password == string.Empty)
               {
                   MessageBox.Show("Please enter an password", "Error");
                   this.txtpass.Focus();

               }


               else if (verify == "" || verify == string.Empty)
               {
                   MessageBox.Show("Please verify your password", "Error");
                   this.txtverify.Focus();

               }

               else if (password.Length < 6)
               {
                   MessageBox.Show("passwords must be at least 6 characters","Error");
                   this.txtpass.Focus();

               }
               else if (verify != password)
               {
                   MessageBox.Show("Passwords must match", "Error");
                   this.txtpass.Focus();

               }

               else if (email == "" || email == string.Empty)
               {
                   MessageBox.Show("Please enter your email address", "Error");
                   this.txtemail.Focus();
               }
               else if (pin == "" || pin == string.Empty)
               {
                   MessageBox.Show("Please enter a security code", "Error");
                   this.txtsecpin.Focus();
               }
               else if (question == "" || question == string.Empty)
               {
                   MessageBox.Show("Please select a security question", "Error");
                   this.cmbsecquestion.Focus();
               }
               else if (answer == "" || answer == string.Empty)
               {
                   MessageBox.Show("Please enter an answer", "Error");
                   this.txtsecanswer.Focus();
               }
               else if(chkterms.Checked == false)
               {
                   MessageBox.Show("You must agree to the terms", "Error");
               }
           else
           {
                   Image noimage = Properties.Resources._default;
                   string q = "insert into impulse_chat.users(ip_address,username,password,email,full_name,age,country,sec_pin,sec_question,sec_answer,profile_pic)values('" + externalIp +"','" + txtuser.Text + "','" + sha1HashStr + "','" + txtemail.Text + "','" + txtfullname.Text + "','" + txtage.Text + "','" + txtcountry.Text + "','" + txtsecpin.Text + "','" + cmbsecquestion.Text + "','" + txtsecanswer.Text + "','" + noimage + "')";
                   ExecuteQuery(q);



                   this.Hide();
                   Form1 frmlogin = new Form1();
                   frmlogin.Show();
               }







任何帮助都会很棒。




Any help would be great.

推荐答案

;

if (!Regex.IsMatch(txtemail。文本,模式))
{
MessageBox.Show( 不是有效的电子邮件地址);
}


string [] stringArray = { admin 所有者 所有者 Admin Mod mod M0d m0d};
foreach string x in stringArray)
{
if (x.Equals(username))
{
// stringToCheck = stringToCheck.Replace(x,****);
MessageBox.Show( 不允许使用该用户名 < span class =code-string>不允许用户名);
}


}
adapter = new MySqlDataAdapter( SELECT`username` FROM`users` WHERE`username` =' + txtuser.Text + ',mcon);

adapter.Fill(table);

如果(table.Rows.Count > = 1
{
MessageBox.Show( 用户名已存在。请重试 用户名存在);
return ;
}

if (用户名== || username == string .Empty)
{
MessageBox.Show( 请输入用户名 错误);
this .txtuser.Focus();



}
else if (密码== || password == string .Empty)
{
MessageBox.Show( 请输入密码 错误);
.txtpass.Focus();

}


else if (verify == || verify == string .Empty)
{
MessageBox.Show( 请验证您的密码 错误);
this .txtverify.Focus();

}

else if (密码。长度< 6
{
MessageBox.Show( 密码必须至少为6个字符 < span class =code-string>错误);
.txtpass.Focus();

}
其他 如果(验证!=密码)
{
MessageBox.Show( 密码必须匹配 错误);
.txtpass.Focus();

}

else if (email = = || email == string .Empty)
{
MessageBox.Show( 请输入您的电子邮件地址 错误);
this .txtemail.Focus();
}
其他 如果(pin == || pin == string .Empty)
{
MessageBox.Show( 请输入安全码 错误);
this .txtsecpin.Focus();
}
else if (question == || question == string .Empty)
{
MessageBox.Show( 请选择安全问题 错误);
this .cmbsecquestion.Focus();
}
else if (answer == || answer == string .Empty)
{
MessageBox.Show( 请输入答案 错误);
.txtsecanswer.Focus();
}
else if (chkterms.Checked == false
{
MessageBox.Show( 你必须同意术语 错误);
}
else
{
Image noimage = Properties.Resources._default;
string q = 插入impulse_chat。用户(ip_address,用户名,密码,电子邮件,full_name,年龄,国家,sec_pin,sec_question,sec_answer,profile_pic)值(' + externalIp + ',' + txtuser.Text + ', ' + sha1HashStr + ',' + txtemail.Text + ',' + txtfullname.Text + ',' + txtage.Text + ', ' + txtcountry.Text + ',' + txtsecpin.Text + < span class =code-string> ',' + cmb secquestion.Text + ',' + txtsecanswer.Text + ',' + noimage + ');
ExecuteQuery(q);



this .Hide();
Form1 frmlogin = new Form1();
frmlogin.Show();
}
"; if (!Regex.IsMatch(txtemail.Text, pattern)) { MessageBox.Show("Not a valid Email address "); } string[] stringArray = { "admin", "owner", "Owner", "Admin","Mod","mod","M0d","m0d" }; foreach (string x in stringArray) { if (x.Equals(username)) { // stringToCheck = stringToCheck.Replace(x, "****"); MessageBox.Show("That username is not allowed","Username not allowed"); } } adapter = new MySqlDataAdapter("SELECT `username` FROM `users` WHERE `username` ='"+ txtuser.Text +"'", mcon); adapter.Fill(table); if (table.Rows.Count >= 1) { MessageBox.Show("Username Already Exists. Please Try Again","Username Exists"); return; } if (username == "" || username == string.Empty) { MessageBox.Show("Please enter an username","Error"); this.txtuser.Focus(); } else if (password == "" || password == string.Empty) { MessageBox.Show("Please enter an password", "Error"); this.txtpass.Focus(); } else if (verify == "" || verify == string.Empty) { MessageBox.Show("Please verify your password", "Error"); this.txtverify.Focus(); } else if (password.Length < 6) { MessageBox.Show("passwords must be at least 6 characters","Error"); this.txtpass.Focus(); } else if (verify != password) { MessageBox.Show("Passwords must match", "Error"); this.txtpass.Focus(); } else if (email == "" || email == string.Empty) { MessageBox.Show("Please enter your email address", "Error"); this.txtemail.Focus(); } else if (pin == "" || pin == string.Empty) { MessageBox.Show("Please enter a security code", "Error"); this.txtsecpin.Focus(); } else if (question == "" || question == string.Empty) { MessageBox.Show("Please select a security question", "Error"); this.cmbsecquestion.Focus(); } else if (answer == "" || answer == string.Empty) { MessageBox.Show("Please enter an answer", "Error"); this.txtsecanswer.Focus(); } else if(chkterms.Checked == false) { MessageBox.Show("You must agree to the terms", "Error"); } else { Image noimage = Properties.Resources._default; string q = "insert into impulse_chat.users(ip_address,username,password,email,full_name,age,country,sec_pin,sec_question,sec_answer,profile_pic)values('" + externalIp +"','" + txtuser.Text + "','" + sha1HashStr + "','" + txtemail.Text + "','" + txtfullname.Text + "','" + txtage.Text + "','" + txtcountry.Text + "','" + txtsecpin.Text + "','" + cmbsecquestion.Text + "','" + txtsecanswer.Text + "','" + noimage + "')"; ExecuteQuery(q); this.Hide(); Form1 frmlogin = new Form1(); frmlogin.Show(); }







任何帮助都会很棒。




Any help would be great.


或许:

Maybe that:
HashSet<string> forbiddenWords = new HashSet<string>({ "admin", "owner", "mod", "m0d" });
if (forbiddenWords.Contains(x.ToLower()))
{
   // stringToCheck = stringToCheck.Replace(x, "****");
   MessageBox.Show("That username is not allowed","Username not allowed");
}





A HashSet< string> 更适合这里,因为它允许你摆脱foreach循环。



如果你想保持foreach循环,你必须放一个休息; MessageBox.Show方法正下方的指令。



A HashSet<string> is more appropriate here, as it allows you to get rid of the foreach loop.

If you want to keep the foreach loop, you have to put a break; instruction right below the MessageBox.Show method.


这篇关于如何修复此注册码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆