现有用户名不适用于某些用户名,为什么? [英] Existing username is not working for some usernames, why?

查看:78
本文介绍了现有用户名不适用于某些用户名,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

地狱般的人,



我有一个网络应用程序,可以检查三个表中是否存在用户。如果用户存在于table2和table3中,则用户可以创建用户名和密码。如果用户存在于table1中,则用户无法创建用户名和密码。到目前为止,这适用于我们测试的一些用户帐户,但在其他帐户上,我们可以使用不同的密码创建双用户名。请让我知道我错在哪里。有没有办法做得更好?



Hell to all,

I have a web app that checks to see if a user exist within three tables. If the user exists in table2 and table3 then the user can create a username and password. If the user exists in table1 then the user can't create a username and password. So far this works on some of the user accounts we have tested but on others, we can create double usernames with different passwords. Please let me know where I am wrong at. Is there a way to do it better?

protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["C3POConnectionString"].ConnectionString);
                con.Open();

                string cmdStr = "Select count(*) from Table1 where EmailAddress='" + TextBoxEA.Text + "'";
                string cmdStr2 = "Select count(*) from Table2 where EmailAddress='" + TextBoxEA.Text + "'";
                string cmdStr3 = "Select count(*) from Table3 where EmailAddress='" + TextBoxEA.Text + "'";

                SqlCommand userExist = new SqlCommand(cmdStr, con);
                SqlCommand userExist2 = new SqlCommand(cmdStr2, con);
                SqlCommand userExist3 = new SqlCommand(cmdStr3, con);

                SqlCommand cmd = new SqlCommand("select USERID, EmailAddress from Table1", con);
                SqlCommand cmd2 = new SqlCommand("select USERID, EmailAddress from Table2", con);
                SqlCommand cmd3 = new SqlCommand("select USERID, EmailAddress from Table3", con);

                userExist.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
                userExist.Parameters.AddWithValue("@Password", TextBoxPW.Text);
                userExist2.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
                userExist2.Parameters.AddWithValue("@Password", TextBoxPW.Text);
                userExist3.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
                userExist3.Parameters.AddWithValue("@Password", TextBoxPW.Text);

                int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
                int temp2 = Convert.ToInt32(userExist2.ExecuteScalar().ToString());
                int temp3 = Convert.ToInt32(userExist3.ExecuteScalar().ToString());

                <pre>if (temp == 1)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Sorry, This User and Passsword Already Exists');", true);
                    TextBoxEA.Text = string.Empty;
                    TextBoxINST_ID.Text = string.Empty;
                    TextBoxaccessLevel.Text = string.Empty;
                    TextBoxEA.Focus();
                }
                else if (temp2 == 1 && temp3 == 1)
                {

                }
                else if (temp2 == 0 || temp3 == 0) 
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name is Not Recognized by the System. Your Accreditation Liaison Officer (ALO) has permissions to this page. Please contact your ALO.');", true);
                    TextBoxEA.Text = string.Empty;
                    TextBoxEA.Focus();
                }
con.Close();
            }
        }





我的尝试:



我试图将代码添加到temp2和temp3,它们不时工作。



What I have tried:

I have tried to add code to the temp2 and temp3 and they work from time to time.

推荐答案

这两行应根据您的要求合并



These two lines should be combine based on your requirement

else if (temp2 == 1)
{

}
else if (temp3 == 1)
{

}






To

else if (temp2 == 1 && temp3 == 1)
{

}



此表可能对您有所帮助你可以更好地想象它


This table might help you visualize it better

temp2 	temp3 	Action
  0 	  0 	  User Name is Not Recognized
  0 	  1 	  User Name is Not Recognized
  1 	  0 	  User Name is Not Recognized
  1 	  1 	  user can create a username and password



然后你可以将代码合并到类似




Then you can consolidate the code to something like

else if (temp2 == 0 || temp3 == 0) 
{
  ScriptManager.....
}


这篇关于现有用户名不适用于某些用户名,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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