Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Chart
Search :       Advanced Search »
Home » Visual Studio .NET » How to use Login Control in Visual Studio 2005

How to use Login Control in Visual Studio 2005

In the recent version of Visual Studio 2005, Microsoft has taken care of a very common functionality of the web applications. In the following article we will see that how to use login control using C#.Net.

Author Rank :
Page Views : 227871
Downloads : 4000
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
WebSite2.zip
 
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


As a web developer we know that most of the time our application is having a login as well as the forget password kind of requirement.

Now, using visual studio 2005 it's very easy to design a login page because the inbuilt login tab has been added into the toolbox of VS 2005 editor, which has different types of control related to login functional.

 L1.gif

Fig 1.1: New tab for login

L2.gif

Fig 1.2: All the controls of Login Tab
 
In the following article we will see that how to use login control using C#.Net. The following code will explain that how to authenticate the user against the database.

Step 1:- Drag and drop the login control on the page then the control will look like a login page at design time.

L3.gif

Fig 1.3: Login control at design time

Step 2: Once the UI is ready then will go ahead with the coding part to see how to write the code for this control.

To write the code for this code we need to handle the Login1_Authenticate event.

So, double click on the Login control it will generate the following code:-

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
          bool Authenticated = false;
          Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
          e.Authenticated = Authenticated;
          if (Authenticated == true)
          {
                    Response.Redirect("Home.aspx");
          }
}
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
{
          bool boolReturnValue = false;
          // Insert code that implements a site-specific custom 
          // authentication method here.
          // This example implementation always returns false.
          string strConnection  = "server=dtpxp-skumari;database=master;uid=sa;pwd=;";
          SqlConnection Connection = new SqlConnection(strConnection);
          String strSQL = "Select * From Employee";
          SqlCommand command =new SqlCommand(strSQL, Connection);
          SqlDataReader Dr;
          Connection.Open();
          Dr=command.ExecuteReader();
          while (Dr.Read())
          { 
                    if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString()))
                    {
                             boolReturnValue = true;
                   
                    Dr.Close();
                    return boolReturnValue;
          }
}

Login control is having a property called FailureText where you can write your own message.

L4.gif

Fig 1.4: Custom Error Message
 
Once you have passed the correct login credential then you will be redirected to the home page using the DestinationPageUrl property. DestinationPageUrl is the property of login control which is used to redirect the user to desination page after a successful login. If incorrect login credential it will show the message like "Your login attempt was not successful. Please try again". This is a custom message specified by the user through the FailureText property.

 L5.gif

Fig 1.5: Logion Error

About inbuilt validation:- Login control is having a inbuilt validation feature which is available as a property for programmer. When you will drag-drop the control at design time you will see that the username and password textboxes are marked with star (*) sign which means these fields are required fields.

 L6.gif

Fig 1.6: Validation

Login control is having some more features like specifying .CSS property, Button style etc.
 
Steps to use the sample:-

  1. Download a zip file --> Unzip the file
  2. Go to Start-->RUN-->inetmgr.exe
  3. Go to Websites-->Default web sites
  4. Right click on it-->NewVirtual Directory-->it will start the wizard
  5. Map the unzip folder with the virtual directory-->finish
  6. Run the application/Open the solution file.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Sushmita Kumari
Sushmita kumari holds  Computer Science degree.She is Brain Bench and Microsoft certified professional. Presently she is working  as a software engineer. She has good hands on experience with .NET technologies. Other than .NET, she has worked with Microsoft Commerce Server, and Microsoft Content Management server.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
hi. your post is so good. by chunsang On February 16, 2006

I read your How to use Login Control in Visual Studio 2005.

thank you very much.

but your article has bad download file.

there are tow WebSite3.sln, WebSite3.suo files.

no aspx, cs files.

please check the other files.

and I must say Thank you. ^^.

- chun sang -

Reply | Email | Modify 
Download file by Douglas On May 24, 2006

I tried to open your example to see the Web.Config because my application don't deny user access to the pages, but the ZIP don't have the files of the project. Can you display the Web.Config?

tanks

 

Reply | Email | Modify 
Re: Download file by Sushmita On June 21, 2006

Long back i have uploaded this file.Now i don't know where is the actual copy in my machine.U just follow the steps and the programe will work if not you ask me i will help u.

Sushmita

Reply | Email | Modify 
How to disable Remember Me Check box? by Srinivas On August 13, 2006

Hi

I don't need the Remember Me option. How to disable 'Remember Me Check box'?

Thanks

Reply | Email | Modify 
Re: How to disable Remember Me Check box? by Hima On October 5, 2006

Set DisplayRememberMe property of the Login Control to false.

Then Check box along with text would be invisible

Reply | Email | Modify 
any more login code? by Pettrer On October 23, 2006

Hi,

Thank you very much for your neat article on using the login control! I made a VB version of it, here it is (in case someone sees this post and needs it in VB): http://forums.asp.net/thread/1431652.aspx

I'm trying to create more of the login controls programatically, as you have been doing (it's the only way - except for rewriting the membership providers that is - to skip the cluttered default db solution provided by Visual Web Developer and to use the login stuff to one's own, existing, db). However, I've run into problems creating the CreateUserWizard (I haven't tried the other controls yet). Do you by any chance have some code for this (or the other controls)?

I think posting code for these controls would benefit a LOT of coders, by judging of the vast amount of questions on this subject on forums.asp.net.

In any case, thanks again for your code + tutorial!

Pettrer, Sweden

 

Reply | Email | Modify 
it is giving error by venkat On October 27, 2006

Hi susmita kumari,

ur article is good,

iam trying to run this application but it is giving error like..

"Not all code paths return a value"

error is rising T,,,

SiteLevelCustomAuthenticatedMethod(string UserName,string Password)

so plz help me..

thanks...

 

Reply | Email | Modify 
thank you, a small typing error by david On November 16, 2006

very nice.

thank you very much.

though you have a small error.

if i run the code the way it is written, i get an error:

"Not All Code Paths Return A Value"  message

that is simply because your :

 return boolReturnValue;

statement is inside the while loop and therefore not all possible values are returned.

simply take this piece of code and place it outside the while loop.

 

p.s : i am sure that it was a typing error.

 

thanks again.

 

Reply | Email | Modify 
Re: thank you, a small typing error by pawan On August 13, 2007

hi

 

use this code , there is minor mistake of not returning false condition ..

 

so i written in the below code ....

 

private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)

{

bool boolReturnValue = false;

string strConnection = "server=(local);database=Northwind;uid=sa;pwd=;";

SqlConnection Connection = new SqlConnection(strConnection);

String strSQL = "Select * From Login1";

SqlCommand command = new SqlCommand(strSQL, Connection);

SqlDataReader Dr;

Connection.Open();

Dr = command.ExecuteReader();

while (Dr.Read())

{

if ((UserName == Dr["username"].ToString()) & (Password == Dr["password"].ToString()))

{

boolReturnValue = true;

}

Dr.Close();

return boolReturnValue;

}

return false;

}

Reply | Email | Modify 
Re: thank you, a small typing error by pawan On August 13, 2007

apply this code , it will run successfully

 

private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)

{

bool boolReturnValue = false;

string strConnection = "server=(local);database=Northwind;uid=sa;pwd=;";

SqlConnection Connection = new SqlConnection(strConnection);

String strSQL = "Select * From Login1";

SqlCommand command = new SqlCommand(strSQL, Connection);

SqlDataReader Dr;

Connection.Open();

Dr = command.ExecuteReader();

while (Dr.Read())

{

if ((UserName == Dr["username"].ToString()) & (Password == Dr["password"].ToString()))

{

boolReturnValue = true;

}

Dr.Close();

return boolReturnValue;

}

return false;

}

Reply | Email | Modify 
how to add our own database in the asp.net configuration provider setting. by rajesh On February 12, 2007
if we set roles an users in the asp.net cofiguration,it creates its own data base an store the user an roles.how to add ourown data base an acess the role an user(in login control)
Reply | Email | Modify 
the zip file empty by mmm On February 26, 2007
and the code not working
Reply | Email | Modify 
hi by Ashwani On March 1, 2007
How to use properly if we simply drag and drop login control it will not work for that we have to use Asp.net configuration so how do use that process please give the detail my id is ashwani.dwivedi@rediffmail.com
Reply | Email | Modify 
Login problem by Hawkmoth On March 20, 2007
I am using the Login contol and everything is working great when I use it localy. When I access the same sight from another pc the login control seems to accept my login but I am unable to get to a authenticated members only page and the loginstatus control suggests I'm not loged in. I guess i have a problem with the way my site is set up or the web.config file is maybe wrong. can anyone help?
Reply | Email | Modify 
Good Article by Chetan On April 9, 2007
Hi Sushmita, This is very good article. I am was very confused regarding how to user login control. This article helped me a lot to start with. Thanks and regards, Chetan Ranpariya.
Reply | Email | Modify 
Error by asp On April 11, 2007

hi there is error when i run the code

while (Dr.Read())

Invalid attempt to Read when reader is closed.

 

please help

Reply | Email | Modify 
Error by asp On April 11, 2007
Reply | Email | Modify 
i am getting an error on this code by Sridhar On April 14, 2007
this is the error - Login.SiteLevelCustomAuthenticationMethod(string , string)':not all code paths return a value
Reply | Email | Modify 
i am getting an error on this code by Sridhar On April 14, 2007
this is the error - Login.SiteLevelCustomAuthenticationMethod(string , string)':not all code paths return a value
Reply | Email | Modify 
Re: i am getting an error on this code by Jayyde On April 18, 2007

Change the code to:

private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)

{

bool boolReturnValue = false;

// Insert code that implements a site-specific custom

// authentication method here.

// This example implementation always returns false.

string strConnection = "server=dtpxp-skumari;database=master;uid=sa;pwd=;";

SqlConnection Connection = new SqlConnection(strConnection);

String strSQL = "Select * From Employee";

SqlCommand command = new SqlCommand(strSQL, Connection);

SqlDataReader Dr;

Connection.Open();

Dr = command.ExecuteReader();

while (Dr.Read())

{

if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString()))

{

boolReturnValue = true;

break;

}

}

Dr.Close();

return boolReturnValue;

}

 

and you'll be fine on the code paths returning a value and the datareader being closed.

Reply | Email | Modify 
Re: Re: i am getting an error on this code by doland On August 11, 2009
hi.. i use this code for our website project... and it work but i have some problems in getting or viewing the userID or the Name of the person who login in the other webform...

applying this code, is there also a c# code that you can view the userID or your name of the user in the texbox in the other webform?...
Reply | Email | Modify 
Re: i am getting an error on this code by mayooran On April 19, 2007
Hi Sridhar, just try with this code. because previous coding have some error and change this sqlconnection string and table name for ur requirements. Here modification on that method for ur error private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password) { bool boolReturnValue = false; // Insert code that implements a site-specific custom // authentication method here. // This example implementation always returns false. string strConnection = "Data Source=MAYOORAN;Initial Catalog=HRMS;Integrated Security=True"; SqlConnection Connection = new SqlConnection(strConnection); String strSQL = "Select * From Login_Table_Ex"; SqlCommand command = new SqlCommand(strSQL, Connection); SqlDataReader Dr; Connection.Open(); Dr = command.ExecuteReader(); while (Dr.Read()) { if ((UserName == Dr["Name"].ToString()) & (Password == Dr["Password"].ToString())) { boolReturnValue = true; break; } } Dr.Close(); return boolReturnValue; } regards, mayooran.
Reply | Email | Modify 
Thanks for your post by Xiaoyan On April 20, 2007
I try to add a query string in the redirect. it works at my local machine, but it did not work after I publish it into our web server. Thanks, June
Reply | Email | Modify 
hi sushmtha by nandha On April 25, 2007
i could not open the source code thanks
Reply | Email | Modify 
Re: hi sushmtha by anji On October 8, 2007

What is the reason for the following code is not working:

Ur's Code:                                                       My Code:            

if (Authenticated == true)        if (Authenticated == true)          

{                                     {  Response.Write("Success"); }

Response.Redirect("Home.aspx");

}

 

 

 

 

Reply | Email | Modify 
Thanks by dost On May 7, 2007
Thanks darling
Reply | Email | Modify 
Disabling Cut/Copy/Paste on Password field by Piyush On May 18, 2007
Hi its very nice article. I want to disable Cut/Copy/Paste into Password field whereas keep enable it into Username field How could i achieve this?
Reply | Email | Modify 
Nice...... by rejaneesh On June 11, 2007
This is something realy very nice 2 understand... U had done a great job.. Congrates...
Reply | Email | Modify 
Regarding Button in Login Control by DVR On June 15, 2007
Hi Sushmita, We are using ASP.NET Login Control. I want to fire a javascript function on click of button in the Login Control. I am unable to attach OnClick Event to that button which is available in Login Control. If u can please help me it will greateful. Thanks DVR Prasad
Reply | Email | Modify 
good job by murugenthiran On June 30, 2007
Hi,It can be easily understandable for those who are new to .net2.0
Reply | Email | Modify 
good job by murugenthiran On June 30, 2007
Hi,It can be easily understandable for those who are new to .net2.0
Reply | Email | Modify 
here is the right bug free code :) by Martin On July 6, 2007
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { bool Authenticated = false; Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password); e.Authenticated = Authenticated; if (Authenticated == true) { Response.Redirect("editing.aspx"); } } private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password) { bool ReturnValue = false; string strConnection = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Data.mdf;Integrated Security=True;User Instance=True"; SqlConnection Conn = new SqlConnection(strConnection); String strSQL = "Select * from Users"; SqlCommand Comm = new SqlCommand(strSQL, Conn); SqlDataReader DReader; Conn.Open(); DReader = Comm.ExecuteReader(); while (DReader.Read()) { if ((UserName == DReader["Uname"].ToString()) & (Password == DReader["Pword"].ToString())) { ReturnValue = true; } } return ReturnValue; DReader.Close(); }
Reply | Email | Modify 
Re: here is the right bug free code :) by Poongundran On August 22, 2007
hi Martin I m new to ASP.NET and i used ur code snippet for Login creation in VS 2005, but still i m getting error,in USER table what r all the fields(columns)should be specified ?I m getting the error as " Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\poongs.mdf".Also another error "An attempt to attach an auto named database with the same name exists or specified is located on UNC .
Reply | Email | Modify 
Thanks Sushmita by arshad On July 12, 2007
i was worried how can i use this control ur article looks can u please send the final code after correction to my email arsmcasa@yahoo and i need the code for sending email in c#.net plz thanks you Arshad
Reply | Email | Modify 
hi by sathish On August 27, 2007
i use login control code.. but here is error... help me how to use login controls in asp.net. give step by step procedure... please
Reply | Email | Modify 
Re: hi by deepa On August 27, 2007

Hi

I am new to dotnet and i am currently working in a web application. So for that i used login control tool from visual studio 2005. But I would like to make each textbox(username and password) to be null when login fails. But right now when login fails, password field becomes null but not the username. So can you please tell me how to do this? i would really appreciate for any kind of help

 

deepa

 

 

Reply | Email | Modify 
getting error on codes by mukesh On September 6, 2007
hi, i have gone through this. but i got an error while trying the codes. its like this.."Error 1 '_Default.SiteLevelCustomAuthenticationMethod(string, string)': not all code paths return a value"
Reply | Email | Modify 
Great post but... by David On November 14, 2007
My application now logs in.. great.. .... if you are the first person in the database table! the datareader doesn't look through all the rows to find the correct user details. could someone please, please help with this asap Thanks David
Reply | Email | Modify 
no files available after download by ruchi On November 21, 2007
hi, itz a gud article. but i cant acces the files in website2.zip after downloading. there are no files in the folder. plz help..
Reply | Email | Modify 
hi by Naresh On December 4, 2007
i had read ur artical but how can i download tghe artical
Reply | Email | Modify 
hi by Naresh On December 4, 2007
i had read ur artical but how can i dodo wnload tghe artical how can i download source code
Reply | Email | Modify 
palaneeswar by Palaneeswar On December 5, 2007
hey that was a gr8 code which made my first strides into logincontrol made a bit easy... but i changed the code a bit... u forgot to close the sqlconnection after opening it..so,i did that in my appication..and sending it..users please change some of the variables as i used them according to my use..thanks sushmitha kumari public bool SiteLevelCustomAuthenticationMethod(string usr, string pwd) { bool boolReturnValue = false; string User = usr; string Passwd = pwd; SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Pubs"].ConnectionString); String strSQL = "Select * From LoginUsers"; SqlCommand command = new SqlCommand(strSQL, Connection); SqlDataReader Dr; try { Connection.Open(); Dr = command.ExecuteReader(); while (Dr.Read()) { if ((User == Dr["Username"].ToString()) & (Passwd == Dr["Password"].ToString())) { boolReturnValue = true; break; } } Dr.Close(); } catch (Exception ex) { Login1.FailureText = ex.Message.ToString(); Response.Redirect("LoginForm.aspx"); } finally { Connection.Close(); } return boolReturnValue; }
Reply | Email | Modify 
abt printing by Raghu On January 10, 2008
am working with win app and i want to print textbox info how can i achive that
Reply | Email | Modify 
user does not stay logged in by Katrin On January 12, 2008
Hi Sushmita, Thanks for the code - it works fine except that when I log on and get redirected the system does not keep the user logged in hence I get redirected to the logon page. Is there anything else I need to do so that a session variable is written? And if I download the source files they are empty... Thanks for you help. Kat
Reply | Email | Modify 
Re: user does not stay logged in by RAVIKUMAR On January 17, 2008
What is the use of Remember me checkbox and then please help me how to use it.
Reply | Email | Modify 
use of remember me by RAVIKUMAR On January 17, 2008
What is the use of Remember me checkbox and then please help me how to use it.
Reply | Email | Modify 
login control by sey On February 1, 2008
Great articale and learning aid for a newbie like me . If someone can post the final bug free version that will be alsome.
Reply | Email | Modify 
request by tariq On February 7, 2008
plz send me complete code of article of login control published in c-sharpcorner.com thanks, harisbscs2003@gmail.com
Reply | Email | Modify 
Remember Me by Uma On February 20, 2008
Can you please tell me the role of Remember me checkbox. And how to use it
Reply | Email | Modify 
login controls by yamunarani On March 14, 2008
i want sample for all login controls
Reply | Email | Modify 
Great Article by Green On September 15, 2008
Short, simple and sweet. This article is gets the job done well.
Reply | Email | Modify 
Great Article by Green On September 15, 2008
Short, simple and sweet. This article is gets the job done well.
Reply | Email | Modify 
Question by Anonymous On November 2, 2008
Hi, what if in case of a successful login, instead of pointing to an url, i want it to point to another visual studio application. How do i do that? Thanks, Abhinav
Reply | Email | Modify 
thanks! by Anonymous On November 7, 2008
hi your post was really helpful. however, in case of successful login, if i want the login system to point to another visual studio application, how do i do that? thanks
Reply | Email | Modify 
Hi by Vikram On November 18, 2008
I read your How to use Login Control in Visual Studio 2005. thank you very much. but your article has bad download file. there are tow WebSite3.sln, WebSite3.suo files. no aspx, cs files. please check the other files. and I must say Thank you. ^^. Vikram Singh Rathore, Mentor, Centre For Electronic Governance, Govt of Raj. Jaipur
Reply | Email | Modify 
i have tried yor code but i am able to use only 1st row of data from database... i m not able to login using data from second row onwards.. can u help me ??? by sanjeev On December 4, 2008
Hi sushmita i have tried yor code but i am able to use only 1st row of data from database... i m not able to login using data from second row onwards.. can u help me ???
Reply | Email | Modify 
hey thanks by sanjeev On December 4, 2008
hey sush i have got it thanks....
Reply | Email | Modify 
hi, by reshma On December 15, 2008
actually i have run your code,but its giving me error,indexOutOfRangeException was handled by usercode.inside the while loop,username and password is it the name of column of login table.pls help me
Reply | Email | Modify 
Got Error:is inaccessible due to its protection level by Benny On December 23, 2008
hi Used this code,but i got this error: is inaccessible due to its protection level can anybody help! ben
Reply | Email | Modify 
VB as the language by Samuel On April 1, 2009
Hi, I'm using VB as my language. Can I use the format you have to login?
Reply | Email | Modify 
Please Help me for solving my first project by amol On May 13, 2010
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace first
{
    
    public partial class Form1 : Form

    {
        public Form1()
        {
           InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        
        {
            

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int Ctr;
            string LoginName, Passoerd;
            LoginName = txtUserName.Text;
            Password = txtPassword.Text;
            Ctr = Ctr + 1;
            if ((LoginName == "sa") && (Password == "callcenter"))
            {
                lblMessage.Visible = true;
                lblMessage.Text = "Welcome to Diaz Telecommunication";
                Ctr = 0;
            }
            else
                if (Ctr < 3)
                {
                    lblMessage.Visible = true;
                    lblMessage.Text = "Incorrect User Name or Password. Please try again.";
                    txtUserName.Focus();
                }
                else
                {
                    MessageBox.Show("Unauthorized Access. Aborting...");
                    Close();
                }

        }
    }
}

Error    1    The name 'Password' does not exist in the current context       42    13    first
Error    2    The name 'Password' does not exist in the current context       44    41    first

Reply | Email | Modify 
not all code paths return a value by islam On June 7, 2010
i have  incorporate the code into my project but there's an error called"Error 44 '_Default.SiteLevelCustomAuthenticationMethod(string, string)': not all code paths return a value D:\Documents and Settings\Eslam\My Documents\Visual Studio 2008\WebSites\project\Default.aspx.cs 38 18 D:\...\project\
"
could you help me fix it
Thanks.
Reply | Email | Modify 
errror by islam On June 7, 2010
i have an error called "Not all code paths returns a value" could you help me to fix it
Reply | Email | Modify 
Re: errror by Sushmita On June 14, 2010
Not sure about your code but if you can use the try/catch blok then it may solve your issue.Use the below catch statement.


catch (Exception ex)
{
Console.Write ("Error in connection : "+ex.Message);
return new SqlCommand();
}
Reply | Email | Modify 
Filtering muliple Dropdownlist by B M On June 22, 2010
Hello mam ur articles and source codes helped a lot.. can u plzz help me filter multiple dropdownlist controls.. how to do it plzz post codes
Reply | Email | Modify 
Hi by Shahid On July 2, 2010
I am new in .net development and start development from 3.5.Today I tried this demo.Its work properly.I am using 3-tier architechure.Can you help me for designing master page for data-driven web application.
Reply | Email | Modify 
Hide the login form when logged by Matteo On August 26, 2010
Hi. I'm a new c# developer and I've got a question for you. I created the login form and it works so well. I put it in my MasterPage. Now, I would hide the form when a user is logged and display a message of welcome. I tried by using visual studio's <LoginView> and <AnonymousTemplate> but it doesn't work. Can you help me?
Thank you so much
Reply | Email | Modify 
Need Help in can u C#Code by murali On August 29, 2010
Hi Susmita,
Am learning C# and needs to create one project in my office,please tell h accme how to create backend database whic accepts the input from backend database to form and stores in backend with login credentials.

It ll be more helpfull if u mail any material to muralits01@gmail.com
Eagerly waiting.
Reply | Email | Modify 
visual web developer inventory by LEx On October 9, 2010
Please Email me a sample program of inventory using visual web developer and sql database
mars_lexter@yahoo.com

thank you.....
Reply | Email | Modify 
error by mithun On November 3, 2010
Hi,
I used the above code to create a login form.But I am getting an error saying: namespace Oledb connection could not be found  ( are you missing a using directive or assembly reference). Could you please help me out...
Reply | Email | Modify 
irrelevant article you can use login control without even one lineof code from web.config membership by jitender On April 10, 2011
http://msdn.microsoft.com/en-us/library/ms178329.aspx The Login control displays a user interface for user authentication. The Login control contains text boxes for the user name and password and a check box that allows users to indicate whether they want the server to store their identity using ASP.NET membership and automatically be authenticated the next time they visit the site. The Login control has properties for customized display, for customized messages, and for links to other pages where users can change their password or recover a forgotten password. The Login control can be used as a standalone control on a main or home page, or you can use it on a dedicated login page. If you use the Login control with ASP.NET membership, you do not need to write code to perform authentication. However, if you want to create your own authentication logic, you can handle the Login control's Authenticate event and add custom authentication code. http://msdn.microsoft.com/en-us/library/ms178329.aspx
Reply | Email | Modify 
control multiply login of one user by Hoa On June 9, 2011
Thankx . I am a new web developer and our application requires to control the multiply login of each users . Means users could not login many times. Could you help me to add a login control multiply login from login.aspx.cs. Hoa
Reply | Email | Modify 
Re: control multiply login of one user by jitender On June 9, 2011
use a login control and have a event fired private bool SiteSpecificAuthenticationMethod(string UserName, string Password) { use a stored procedure to return false value if user is online and show error message saying user already logged in http://blog.dreamlabsolutions.com/post/2009/07/13/ASPNET-Membership-Show-list-of-users-online.aspx try this to know if user which is try to login is already logged in you can use Login1.UserName and pass it as parameter return false; } private void OnAuthenticate(object sender, AuthenticateEventArgs e) { bool Authenticated = false; Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password); e.Authenticated = Authenticated; } you can contact me through Jin_us@yahoo.com
Reply | Email | Modify 
Re: Re: control multiply login of one user by Hoa On June 9, 2011
Thank you very much. I am using .net2 & visual studio 2005. I iinherit this application .and I need to modify control multiply login. This database is already have aspnet_Membership_GetNumberOfUsersOnline. Application have the program Web.Security.membershipProvider.cs with public override int GetMunberOfUsersOnline() --> cmd.ExecuteNonQuery(); Would you please shows me how to add in the login.aspx.cs or any progam to fix this problem. Thanh again for your help. Hoa
Reply | Email | Modify 
DevExpress Free UI Controls
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.