Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
i want a coding or a design page for a login page in which where we are already make a database or we are already inserted the value of username or password in our database when we want to login in the runtime we have to inserted those value which are already in the database
Posted 31-Mar-10 20:19pm
Edited 31-Mar-10 20:25pm
Ankur\m/49.3K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hello am showing u an example how this thing is done the database i have used is Access 2003 and its in ASP.NET u can do the same thing in VC# only the thing is u have to change some lines let me show u
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public static string getconnection()
{
return @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Registration form\ASP.NET.mdb;Persist Security Info=False";
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = getconnection();
con.Open();
string command = "select * from mytable where Myname=@name and Password=@pass";
OleDbCommand cmd = new OleDbCommand(command,con);
cmd.Parameters.AddWithValue("@name", txtusername.Text);
cmd.Parameters.AddWithValue("@pass", txtpassword.Text);
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read() == true)
{
/*if ur using vc# i.e. GUI then u can add a msg box here at the place of Response.Redirect*/
Response.Redirect("Default2.aspx");
}
else
{
txtusername.Text = "unknown user";
}
con.Close();
 

}
}
 

and if ur database is SQL the at the place of OleDb jsut add SQL thats it and use the namespace
using System.Data.SqlClient;
 
and change the conncetion String to
 
SqlConnection connect = new SqlConnection();
connect.ConnectionString = "Data Source=.;Initial Catalog=master;Integrated Security=True";
 
The Remaining Method is same
 
now if the table u made is in master database then use master else in the place of master u can give ur database name.
 
Do Rate my answer once u find it useful
 
Thanks & Regards
Radix Rose | [Rose]
  Permalink  
v2
Comments
Richard MacCutchan at 16-Oct-11 8:46am
   
Please use <pre> tags around your code and do not use txtspk (u, ur etc.) in your answers.
Farzad Wadia at 15-Mar-12 9:17am
   
Thank you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Looks like you need a sample code for login page that interacts with SQL in order to authneticate:
http://www.daniweb.com/forums/thread24148.html[^]
 
If you need more, just use google... you will find ample material on it. Thumbs Up | :thumbsup:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        con.Open()
        cmd = New SqlCommand("select * from login where username='" + UsernameTextBox.Text.ToString + "' and password='" + PasswordTextBox.Text.ToString + "'", con)
        dReader = cmd.ExecuteReader()
        If dReader.Read = True Then
            MDIParent1.Show()
            Me.Hide()
            con.Close()
        Else
            MsgBox("sorry")
        End If
        con.Close()
    End Sub
 
tryyyyyyyyyyy it
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 

    protected string Getconnection()
    {
        
     
        return System.Configuration.ConfigurationManager.ConnectionStrings["subhacon"].ConnectionString;
    
    }
 
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            SqlConnection con = new SqlConnection(Getconnection());
 
            con.Open();
            SqlCommand com = new SqlCommand("select * from login where uname= @uname and pass= @pass", con);
            
 
            com.Parameters.AddWithValue("@uname", TextBox1.Text);
 
            com.Parameters.AddWithValue("@pass", TextBox2.Text);
 

            if(con!=null)
                Response.Write("conn success");
 
                SqlDataReader dr = com.ExecuteReader();
 
            if (dr.Read()==true)
            {
                Response.Redirect("http://google.com");
                Response.Write("login success");
            }
 
            else
                Response.Write("login failed");
        }
        catch (Exception ex)
        {
            Response.Write("error");
        }
 

        
    }
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 363
1 OriginalGriff 344
2 George Jonsson 248
3 Shemeemsha RA 138
4 Animesh Datta 130
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 16 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100