登录问题? [英] problem for login ?

查看:56
本文介绍了登录问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要登录表单的代码,我有stutus(管理员,用户),当管理员页面的管理员响应的uesername文本和密码,以及用户响应用户页面的uesername文本和密码?



如何???



我的代码有问题:



i need code for login form , i have stutus (admin , user ) ,when uesername text and password for admin response to admin page , and when uesername text and password for users response to user page ?

how ???

this my code and have problem :

Session("username") = usernametxt.Text
        Session("password") = passwordtxt.Text

        Try
            If conn.State = False Then conn.Open()

            Try
                com.Connection = conn
                com.CommandType = CommandType.Text
                cmd = "select password,stutus from [Users] where ( username='" & usernametxt.Text & "' )"
                com.CommandText = cmd
                dr = com.ExecuteReader

                Do While dr.Read
                    cmd = dr(0)
                    stutus = dr(1)
                Loop
                dr.Close()
                conn.Close()

                If cmd = passwordtxt.Text Then

                    If stutus = "admin" Then
                        Session("username") = usernametxt.Text
                        Session("password") = passwordtxt.Text
                        Me.Response.Redirect("reply page.aspx")

                    ElseIf stutus = "active user" Then
                        Session("username") = usernametxt.Text
                        Session("password") = passwordtxt.Text
                        Me.Response.Redirect("map upload.aspx")

                    ElseIf stutus = "unuser" Then
                        Label2.ForeColor = System.Drawing.Color.Green
                        Label2.Text = "حسابك معطل يرجى مراسلة ادارة الدليل "
                        usernametxt.Focus()
                    End If

                Else
                    Label2.ForeColor = System.Drawing.Color.Green
                    Label2.Text = "لا يوجد لك حساب بالدليل ، الرجاء الضغط على طلب اشتراك في اعلى الصفحة للحصول على حساب "
                    usernametxt.Focus()
                End If
                If usernametxt.Text = Nothing And passwordtxt.Text = Nothing Then
                    Label2.Text = "الرجاء ادخال اسم المستخدم وكلمة المرور في الحقول اعلاه"
                    usernametxt.Focus()
                End If

            Catch ex2 As SqlException
                MsgBox(ex2.Message)
            End Try
        Catch ex2 As SqlException
            MsgBox(ex2.Message)
        End Try





[edit]已添加代码块[/ edit]



[edit]Code block added[/edit]

推荐答案

protected void btnsubmit_Click(object sender, EventArgs e)
    {
        string login_name = txtuser_name.Text;
        string password = txtpwd.Text;
        string constr = ConfigurationManager.ConnectionStrings["connstr"].ToString();
        SqlConnection con = new SqlConnection(constr);
        con.Open();
        string sql = "SELECT user_name, pwd FROM admin WHERE (user_name='" + txtuser_name.Text + "') AND (pwd='" + txtpwd.Text + "') ";
        SqlCommand cmd = new SqlCommand(sql, con);
        string currentname = (string)cmd.ExecuteScalar();
        if (currentname != null)
        {
            
            Session["admin"] = sql;
            Response.Redirect("viewreport.aspx");
        }
        else
        {
            
            lblmsg.Visible = true;
            lblmsg.Text = "Incorrect username or password";
        }
    }


这篇关于登录问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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