I want to make sessions, but i don't know from where I can start. I logged in myself, but without using session and i have to make sessions. Below is my code which I have done so far.
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogin.Click
If txt_username.Text = "" Or txt_password.Text = "" Then
error_usr_invalid.Visible = False
If txt_username.Text = "" Then
error_usr_blank.Visible = True
ElseIf txt_username.Text <> "" Then
error_usr_blank.Visible = False
End If
If txt_password.Text = "" Then
error_pwd_blank.Visible = True
ElseIf txt_username.Text <> "" Then
error_pwd_blank.Visible = False
End If
ElseIf txt_username.Text <> "" And txt_password.Text <> "" Then
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
con.Open()
Dim cmd As New SqlCommand("select * from users where username = '" + txt_username.Text + "' and Password = '" + txt_password.Text + "'", con)
cmd.Parameters.AddWithValue("@username", txt_username.Text)
cmd.Parameters.AddWithValue("@password", txt_password.Text)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
If dt.Rows.Count > 0 Then
error_usr_invalid.Visible = False
error_usr_blank.Visible = False
error_pwd_blank.Visible = False
Response.Redirect("main.aspx")
Else
error_usr_invalid.Visible = True
error_usr_blank.Visible = False
error_pwd_blank.Visible = False
End If
End If
Please help me out by suggesting your ideas in this code.