Welcome to Dream.In.Code
Become an Expert!

Join 150,397 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,010 people online right now. Registration is fast and FREE... Join Now!




login form

 
Reply to this topicStart new topic

login form

yaseenmsc
7 Mar, 2008 - 10:30 AM
Post #1

New D.I.C Head
*

Joined: 7 Mar, 2008
Posts: 1

vb

Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page

Dim strcon As String = "provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\\project.mdb"
Dim con As OleDbConnection
Dim da As OleDbDataAdapter
Dim dr As OleDbDataReader

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
con = New OleDbConnection(strcon)
da = New OleDbDataAdapter("select *from login", con)
con.Open()
dr = da.SelectCommand.ExecuteReader()
If dr.Read Then
dr.GetString(0) = Session("userid")
dr.Item(1) = Session("pwd")

Response.Redirect("hopme.aspx")

End If
dr.Close()

End Sub
End Class


This post has been edited by PsychoCoder: 8 Mar, 2008 - 03:54 PM
User is offlineProfile CardPM
+Quote Post

bhandari
RE: Login Form
7 Mar, 2008 - 10:35 AM
Post #2

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
hi yaseenmsc,

welcome to <DIC>

can u please explain the error with your code for helping us to help u
User is offlineProfile CardPM
+Quote Post

vamsi kare
RE: Login Form
12 Mar, 2008 - 11:37 PM
Post #3

New D.I.C Head
*

Joined: 11 Mar, 2008
Posts: 4

Hi,

Below is the code for checking against user name and password in asp.net and sql server {Link Removed}

CODE



<h2>Login</h2>

<b>Username:</b>
<br/>
<asp:TextBox
  ID="txtUsername"
  CssClass="formfield"
  runat="Server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
  ControlToValidate="txtUsername"
  Text="Required!"
  runat="Server" />
<br />

<asp:Label
  ID="lblError"
  EnableViewState="False"
  forecolor="red"
  font-bold="True"
  runat="Server" />
<br />

<b>Password:</b>
<br/>
<asp:TextBox
  ID="txtPassword"
  TextMode="password"
  CssClass="formfield"
  runat="Server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
  ControlToValidate="txtPassword"
  Text="Required!"
  runat="Server" />

<br />
<asp:CheckBox Text="Automatically remember me"
  ID="chkPersist"
  Checked="True"
  runat="Server" />


<br /><br />
<asp:Button ID="Button1"
  Text="Login!"
  OnClick="Button_Click"
  runat="Server" />




void Button_Click(object sender, System.EventArgs e)
{

if (Page.IsValid)
{
switch (VerifyPassword( txtUsername.Text, txtPassword.Text )) {
        case 0:
            FormsAuthentication.RedirectFromLoginPage( txtUsername.Text, chkPersist.Checked );
            break;
        case 1:
            lblError.Text = "You did not enter a valid username";
            break;
        case 2:
            lblError.Text = "You did not enter a valid password";
            break;
    }
  
}
}

int VerifyPassword( string strUsername, string strPassword ) {
  string strConString;
  SqlConnection conJobs;
  SqlCommand cmdVerify;
  SqlParameter parmReturn;
  
  strConString = "Data Source=202.71.129.59;database=jobskenabc;User ID=jobsken123;Password=cd546dc;";
  conJobs = new SqlConnection( strConString );
  cmdVerify = new SqlCommand( "VerifyPassword", conJobs );
  cmdVerify.CommandType = CommandType.StoredProcedure;
  parmReturn = cmdVerify.Parameters.Add( "@return", SqlDbType.Int );
  parmReturn.Direction = ParameterDirection.ReturnValue;
  cmdVerify.Parameters.Add( "@username", strUsername );
  cmdVerify.Parameters.Add( "@password", strPassword );
  conJobs.Open();
    cmdVerify.ExecuteNonQuery();
  conJobs.Close();
  return (int)cmdVerify.Parameters["@return"].Value;
}
</script>




The above code check username and password against database.


In the statement, FormsAuthentication.RedirectFromLoginPage, FormsAuthentication is the class and RedirectFromLoginPage is the method. Calling the RedirectFromLoginPage method performs two actions. First, it creates a cookie on the user's browser that contains an Authentication Ticket. chkPersist. The statement Checked is true, it creates persistent cookie otherwise session cookie. Second :the RedirectFromLoginPage method also automatically redirets the user back to the page that sent him to the Login.aspx page in the first place by using a browser redirect.

This post has been edited by PsychoCoder: 13 Mar, 2008 - 04:06 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 06:36PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month