473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Login controls

11 New Member
Hi,

I am new to asp.net. I created an application using login controls.Now I have a problem. In SQLserver I have a database. In that I created a signup table.
the data which I enter in sign up application which contains username,passwo rd and email are stored in to that table.when user wants to login he enters username and password, Now these username and password values check with all the values in the table. If this username and password are in table, then user goes to next page, other wise A error message should be thrown. How the code for this.can you help me.
Nov 20 '07 #1
4 1288
shweta123
692 Recognized Expert Contributor
Hi,

You can do it like this way ,
e.g. You have taken Login control called as Login1

Expand|Select|Wrap|Line Numbers
  1.  
  2.      Dim Comm as new OleDbCommand
  3.     Comm.CommandText = "Select loginame from signup where login_name = '" & Login1.UserName.Trim & "' and password ='" & Login1.Password.Trim & "' "
  4.  
  5.             Comm.CommandType = CommandType.Text
  6.             Comm.Connection = conn
  7.  
  8.            Dim login_name as string = ""
  9.             If Not IsNothing(Comm.ExecuteScalar()) Then
  10.                  login_name = Comm.ExecuteScalar().ToString()
  11.            End If
  12.  
  13.             If  login_name = "" Then
  14.                 ''''''''Display Error Message , if loginId does not exist
  15.             Else
  16.                     '''''''Redirect to the page you want
  17.                   Response.Redirect("Someotherpage.asp")
  18.             End If
  19.  
Hi,

I am new to asp.net. I created an application using login controls.Now I have a problem. In SQLserver I have a database. In that I created a signup table.
the data which I enter in sign up application which contains username,passwo rd and email are stored in to that table.when user wants to login he enters username and password, Now these username and password values check with all the values in the table. If this username and password are in table, then user goes to next page, other wise A error message should be thrown. How the code for this.can you help me.
Nov 20 '07 #2
aaronsandoval
13 New Member
There are many ways to approach this scenario and accomplish what you are trying to write. The above sample code posted by shweta123 is a nice example but I do recommend a little different road to take.

This example above uses in-line SQL statements, one major mistake if you want to become victim of SQL injection attacks. But it really just depends on how secure and "code tight" you want your application. In the beginning, I think every developer used in-line SQL but as we continue to learn from others and keep an open mind every developer I know uses stored procedures to accomplish these types of tasks.

I am going to provide you an example of how my team would write out this type of EXAMPLE code to check the database for User Name, Password and Email so we can continue with the script. We would have all of this code broken down into different layers (Data Access, Business Logic and Presentation) but this is a simple code example.

THIS EXAMPLE BELOW IS RELATED TO SIGNING UP A USER, BUT YOU CAN GATHER THE SYNTAX FROM IT TO CHECK WHETHER THE USERS USERNAME AND PASSWORD ARE CORRECT.

DATABASE TABLE
Expand|Select|Wrap|Line Numbers
  1. App_Users (DATABASE TABLE)
  2. UserID (integer)
  3. UserName (nvarchar(64))
  4. UserPassword (nvarchar(256))
  5. UserEmail (nvarchar(50))
  6.  
DATABASE STORED PROCEDURE
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE [App_Users_SignUpUser]
  2. (
  3. @UserName nvarchar(64),
  4. @UserPassword nvarchar(256),
  5. @UserEmail nvarchar(50)
  6. )
  7. AS
  8. IF EXISTS(SELECT UserID FROM App_Users WHERE UserName = @UserName OR UserEmail = @UserEmail)
  9. BEGIN
  10. -- USER EXISTS SO THROW ERROR IN CODE MATCHING VALUE USEREXISTS AND HAVE USER FILL OUT DIFFERENT INFORMATION
  11. -- return table 1
  12. SELECT 'UserExists' AS 'STATUS'
  13. END
  14. ELSE
  15. BEGIN
  16. -- USER DOES NOT EXIST YOU CAN CONTINUE CREATING NEW USER
  17. -- return table 1
  18. SELECT 'NoUserExisted' AS 'STATUS'
  19. -- insert new user information into table
  20. INSERT INTO App_Users ( UserName, UserPassword, UserEmail ) VALUES ( @UserName, @UserPassword, @UserEmail )
  21. END
  22. GO
  23.  
C# ASP.NET 2.0 CODE
Assuming you already have these items below here is the code behind page:
  1. Three textbox server controls and a button on the page with the OnClick event equal to btnSignIn_Click
  2. Downloaded SQL Helper from Microsoft (I can provide this if needed)
  3. You have a connection string declared in your web.config
Expand|Select|Wrap|Line Numbers
  1. public DataSet App_Users_SignUpUserMethod(string userName, string userPassword, string userEmail)
  2. {
  3.     DataSet ds = new DataSet();
  4.  
  5.  
  6.     try
  7.     {
  8.         // this sets up connection string from web.config file
  9.         // in order for the configuration manager to display, you
  10.         // must declare using System.Configuration namespace at top of page
  11.         string strMyConnectionString =    ConfigurationManager.ConnectionStrings["MY_DB_CONN"].ConnectionString;
  12.  
  13.         // this sqlhelper saves lots of time
  14.         ds = SqlHelper.ExecuteDataset(strMyConnectionString, "App_Users_SignUpUser", userName, userPassword, userEmail);
  15.      }
  16.     catch (Exception ex)
  17.     {
  18.         throw new Exception(ex.Message);
  19.     }
  20.  
  21.     return ds;
  22.  
  23. protected void btnSignIn_Click (object sender, EventArgs e)
  24. {
  25.     string userName = txtUserName.Text.Trim(); string userPassword = txtUserPassword.Text.Trim();string userEmail = txtUserEmail.Text.Trim();
  26.  
  27.     DataSet ds;
  28.     ds = App_Users_SignUpUserMethod(userName, userPassword, userEmail);
  29.  
  30.     // this STATUS is what is returned from the stored procedure
  31.     string status = ds.Tables[0].Rows[0]["STATUS"].ToString();
  32.  
  33.     // now we want to specify what we are doing next depending
  34.     // on what status was returned from the database
  35.     try
  36.     {
  37.         switch (status)
  38.         {    case "NoUserExisted":
  39.             // now you can write your method here for next step
  40.             // maybe you want to redirect them to thank you page
  41.             // note: this information has been inserted
  42.             // into the database because the user did not exist
  43.  
  44.             case "UserExists":
  45.             // now because a user exists with this information
  46.             // you may want to let them know in a label server control
  47.             lblMessage.Visible = true;
  48.             // in order for color.red to show, you must declare
  49.             // using System.Drawing namespace at top of page
  50.             lblMessage.ForeColor = Color.Red;
  51.             lblMessage.Text = "User Name / Email Already Exists";
  52.              break; 
  53.         }
  54.     }
  55.     catch (Exception ex)
  56.     {
  57.             throw new Exception(ex.Message);
  58.     }
  59.  
SHORT ENDING
Please remember every developer has their own style of coding. So once you find yours, you will be able to accomplish anything you set your mind to and be able to do it in your own way. This example is simply how we would have written it quickly. Also, of course I don't recommend using raw text for passwords stored in database neither so you may want to look into Rijndael Encryption Methods to encrypt the users passwords.

ALSO, IF YOU WANT AN EXAMPLE ON FORMS AUTHENTICATION WE MAY WANT TO TYPE IT UP IN A DIFFERENT THREAD.
Nov 20 '07 #3
Frinavale
9,735 Recognized Expert Moderator Expert
There are many ways to approach this scenario and accomplish what you are trying to write. The above sample code posted by shweta123 is a nice example but I do recommend a little different road to take.

This example above uses in-line SQL statements, one major mistake if you want to become victim of SQL injection attacks. But it really just depends on how secure and "code tight" you want your application. In the beginning, I think every developer used in-line SQL but as we continue to learn from others and keep an open mind every developer I know uses stored procedures to accomplish these types of tasks.

I am ...
Way to go Aaronsandoval!
Your response was very impressive.
Thanks

-Frinny
Nov 20 '07 #4
shilpareddy2787
11 New Member
Thank you for your help.it is very helpful for me.
Nov 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1203
by: Ash | last post by:
I want to provide the ability for my users to login from any page that they are on. ie. have a login user control with a username and password box on each page (not a link to a login page). However, as the values of other controls on the page , and whether these controls are displayed, rely on whether the user is logged in, I need to get the UserID before the controls are created. I suppose that I could set these properties in the...
5
1731
by: RedEye | last post by:
Hello, I am working on a test site to explore the new login controls and membership features of ASP.NET v2.0. I have tested the controls using SQL Express and have now decided to try using a central SQL Server 2000 database. When I use the all of the included controls with SQL Express everything works great but when I use it against SQL Server 2000 I can't get past the login page. When in Visual Studio IDE and open the web admin page I...
14
2624
by: clintonG | last post by:
This is an appeal for peer support sent to Microsoft as will be noted in closing. The Login control does not include a Cancel button. The only option is to convert the Login control to a template which is not such a bad thing in itself but it means all other controls in the application must also be converted to templates to maintain a consistent UI. So much for writing 70% less code when foolish morons release a control with no cancel...
3
3831
by: Brian Henry | last post by:
I have an existing user managment system that has been in our asp.net 1.1 app for a couple years now, all the user managment is done through an application that is a win form, and stored in SQL Server. I want to see if I can at all use the new login controls with my existing scheme for user managment... Is there a way to use your own system with these controls or do you have to use ASP.NET's managment of users to use these controls?...
5
1561
by: John | last post by:
Hi What db does the built-in user control in asp.net uses? sql server? Access? is it possible to choose? Thanks Regards
5
1990
by: Ronald S. Cook | last post by:
It's been longer that I remember since writing windows (not web) apps. 1) I want to load a main form 2) User clicks login button which brings up login form (on top of main form) 3) Upon entering successful password and clicking ok, login form should go away 4) Main form should then display admin controls
3
7130
by: ad | last post by:
I have create a custom membership provider. The common usage of custom membership is set it as default Membership Provider win web.config, and use login controls with it. How can I use custom membership provider without Login Controls? For example, the name of my custom membership provider MyMembershipProvider. Is the codes below right? MyMembershipProvider myProvider=new MyMembershipProvider();
1
2044
by: frolda | last post by:
Hi, I moved my login.aspx page from root to a subdirectory and made -hopefully- all necessary changes for all Login controls. All the controls work just fine, except one. To my regret, the LoginStatus control still uses the old, root-located login.aspx intead of subdir/login.aspx. What's interesting is that for logout it works perfectly (path to subdir/logout.aspx is recognized OK). Could anyone write me please, where does the...
1
6430
by: pj | last post by:
I'm trying to redirect users to another page after they Authenticate with the ASP.NET login controls. The user is able to login, but I can't get the response.redirect to work. Can anyone help? My code is below. Thanks, pj mcdba, mcp
2
1786
by: mdavis | last post by:
Hello, I'm using a Login Control on asp.net 2.0 website and it works fine on IE & Firefox, however I have recently added a javscript function to listen for a 'return-key-click' and am encountering problems with Firefox. If the user clicks the 'Login' button with a mouse button click, it works fine, however if the user hits enter, the form fields are cleared and the user is not logged in. Please note, this only happens if the user has...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.