Click here to Skip to main content
16,020,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :

VB
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]Code block added[/edit]
Posted
Updated 26-Aug-13 23:01pm
v2

1 solution

C#
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";
        }
    }
 
Share this answer
 
v2
Comments
ahmed200 27-Aug-13 5:48am    
read my code please .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900