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.
4 1288
Hi,
You can do it like this way ,
e.g. You have taken Login control called as Login1 -
-
Dim Comm as new OleDbCommand
-
Comm.CommandText = "Select loginame from signup where login_name = '" & Login1.UserName.Trim & "' and password ='" & Login1.Password.Trim & "' "
-
-
Comm.CommandType = CommandType.Text
-
Comm.Connection = conn
-
-
Dim login_name as string = ""
-
If Not IsNothing(Comm.ExecuteScalar()) Then
-
login_name = Comm.ExecuteScalar().ToString()
-
End If
-
-
If login_name = "" Then
-
''''''''Display Error Message , if loginId does not exist
-
Else
-
'''''''Redirect to the page you want
-
Response.Redirect("Someotherpage.asp")
-
End If
-
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.
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 -
App_Users (DATABASE TABLE)
-
UserID (integer)
-
UserName (nvarchar(64))
-
UserPassword (nvarchar(256))
-
UserEmail (nvarchar(50))
-
DATABASE STORED PROCEDURE -
CREATE PROCEDURE [App_Users_SignUpUser]
-
(
-
@UserName nvarchar(64),
-
@UserPassword nvarchar(256),
-
@UserEmail nvarchar(50)
-
)
-
AS
-
IF EXISTS(SELECT UserID FROM App_Users WHERE UserName = @UserName OR UserEmail = @UserEmail)
-
BEGIN
-
-- USER EXISTS SO THROW ERROR IN CODE MATCHING VALUE USEREXISTS AND HAVE USER FILL OUT DIFFERENT INFORMATION
-
-- return table 1
-
SELECT 'UserExists' AS 'STATUS'
-
END
-
ELSE
-
BEGIN
-
-- USER DOES NOT EXIST YOU CAN CONTINUE CREATING NEW USER
-
-- return table 1
-
SELECT 'NoUserExisted' AS 'STATUS'
-
-- insert new user information into table
-
INSERT INTO App_Users ( UserName, UserPassword, UserEmail ) VALUES ( @UserName, @UserPassword, @UserEmail )
-
END
-
GO
-
C# ASP.NET 2.0 CODE
Assuming you already have these items below here is the code behind page: - Three textbox server controls and a button on the page with the OnClick event equal to btnSignIn_Click
- Downloaded SQL Helper from Microsoft (I can provide this if needed)
- You have a connection string declared in your web.config
-
public DataSet App_Users_SignUpUserMethod(string userName, string userPassword, string userEmail)
-
{
-
DataSet ds = new DataSet();
-
-
-
try
-
{
-
// this sets up connection string from web.config file
-
// in order for the configuration manager to display, you
-
// must declare using System.Configuration namespace at top of page
-
string strMyConnectionString = ConfigurationManager.ConnectionStrings["MY_DB_CONN"].ConnectionString;
-
-
// this sqlhelper saves lots of time
-
ds = SqlHelper.ExecuteDataset(strMyConnectionString, "App_Users_SignUpUser", userName, userPassword, userEmail);
-
}
-
catch (Exception ex)
-
{
-
throw new Exception(ex.Message);
-
}
-
-
return ds;
-
}
-
-
protected void btnSignIn_Click (object sender, EventArgs e)
-
{
-
string userName = txtUserName.Text.Trim(); string userPassword = txtUserPassword.Text.Trim();string userEmail = txtUserEmail.Text.Trim();
-
-
DataSet ds;
-
ds = App_Users_SignUpUserMethod(userName, userPassword, userEmail);
-
-
// this STATUS is what is returned from the stored procedure
-
string status = ds.Tables[0].Rows[0]["STATUS"].ToString();
-
-
// now we want to specify what we are doing next depending
-
// on what status was returned from the database
-
try
-
{
-
switch (status)
-
{ case "NoUserExisted":
-
// now you can write your method here for next step
-
// maybe you want to redirect them to thank you page
-
// note: this information has been inserted
-
// into the database because the user did not exist
-
-
case "UserExists":
-
// now because a user exists with this information
-
// you may want to let them know in a label server control
-
lblMessage.Visible = true;
-
// in order for color.red to show, you must declare
-
// using System.Drawing namespace at top of page
-
lblMessage.ForeColor = Color.Red;
-
lblMessage.Text = "User Name / Email Already Exists";
-
break;
-
}
-
}
-
catch (Exception ex)
-
{
-
throw new Exception(ex.Message);
-
}
-
}
-
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.
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
Thank you for your help.it is very helpful for me.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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?...
|
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
| |
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
|
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();
|
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...
|
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
|
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...
|
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...
| |
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,...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |