Introduction
As we know on internet world without security we can not expect any thing. At
least on every website we use to face such like to create account but as far we
concern to learn how to create it then without any good guidelines we can't.
Let's take a look on this article to create such project.
Perquisite
This article expect something from you as
- You should know MS-SQL Server
- You should have the basic knowledge of ASP.Net controls
Creating Database
To store the user's credentials for future login, we should have database. So,
let's create it.
Database Name: myDb.mdf
Table Name: myTb
Column Names:
| Column Name | Data Type | Required or Not |
| name | varchar(50) | Not Checked |
| username | varchar(50) | Not Checked |
| password | varchar(50) | Not Checked |
| emailed | varchar(100) | Not Checked |

Creating Database Configuration in web.config file
To create database configuration in web.config file, simply drag the 'myTb'
table from Database Explorer on any form and now delete the dragged item from
web page, it will create the configuration settings for your database in web.config file automatically.

Here is your configuration in web.config file
<connectionStrings>
<add
name="myDbConnectionString1"
connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\myDb.mdf;Integrated
Security=True;User Instance=True"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
Create User Form Designing
To create or register new user we should have a form as given below. You can
ignore the side links, top banner and footer texts because they are occurring
from master page.

| Control Name | ID | Other |
| TextBox | name | |
| TextBox | username | |
| TextBox | password | Textmode=password |
| TextBox | emailed | |
| Button | create | Text=Create User |
To call for the database configuration setting from web.config file I have used
a function
public
string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["myDbConnectionString1"].ConnectionString;
}
I have used a execute named function in code behind to perform the insertion
task when 'Create User' named button clicked
private
void execution(string
name, string username,
string password, string emailid)
{
SqlConnection conn =
new SqlConnection(GetConnectionString());
string sql =
"INSERT INTO myTb (name, username, password, emailid) VALUES "
+ " (@name, @username, @password, @emailid)";
try
{
conn.Open();
SqlCommand
cmd = new SqlCommand(sql,
conn);
SqlParameter[] pram =
new SqlParameter[4];
pram[0] =
new SqlParameter("@name",
SqlDbType.VarChar, 50);
pram[1] = new
SqlParameter("@username",
SqlDbType.VarChar, 50);
pram[2] = new
SqlParameter("@password",
SqlDbType.VarChar, 50);
pram[3] = new
SqlParameter("@emailid",
SqlDbType.Char, 10);
pram[0].Value = name;
pram[1].Value = username;
pram[2].Value = password;
pram[3].Value = emailid;
for
(int i = 0; i < pram.Length; i++)
{
cmd.Parameters.Add(pram[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException
ex_msg)
{
string msg =
"Error occured while inserting";
msg += ex_msg.Message;
throw new
Exception(msg);
}
finally
{
conn.Close();
}
}
Finally I have used to following code in 'Create User' button click event. In
this event we have to check the database for the duplication. Because in login
project duplications are never assumed even. If there is no any duplication
found in code behind will create a new account. Here it is
protected
void create_Click(object
sender, EventArgs e)
{
SqlDataSource sds =
new SqlDataSource();
sds.ConnectionString = ConfigurationManager.ConnectionStrings["myDbConnectionString1"].ToString();


Pankaj KadamPosted Jan 12, 2016, 1:59 AM
Abhimanyu can u please share the same in MVC 4 with master page with nice look and feel
Pankaj KadamPosted Jan 12, 2016, 1:59 AM
Abhimanyu K Vatsa@Abhimanyu K Vatsa
muhamaad waqasPosted Feb 27, 2015, 8:57 AM
how to create discussion forum in asp.net
muhamaad waqasPosted Feb 27, 2015, 8:57 AM
Nice
hothorasman panjaitanPosted Dec 1, 2014, 2:39 AM
how to save a multi files at once in asp.net
Manish Kumar ChoudharyPosted Nov 19, 2014, 6:12 AM
Nice Abhimanyu K Vatsa sir..
hothorasman panjaitanPosted May 11, 2014, 3:29 PM
hello Abhimanyu K Vatsa. what if the user is not logged in then the user can not access the pages in the next
Emanuel SherpaPosted Jun 5, 2013, 4:17 AM
well nice but ....keep it up
Kaneshapillai SathulanPosted Apr 24, 2013, 9:37 AM
can you explain c#.net 2010 and mssql 2008 windows form desin and give me full source code
Abhimanyu K VatsaPosted Mar 15, 2013, 8:30 AM
@Tim G: no its not, the textbox data is hardcoded
Tim GPosted Feb 14, 2013, 9:13 AM
Is this method of creating a user/logging in protected from sql injection?
Former memberPosted Oct 2, 2012, 2:39 AM
Hi....This is really nice article. http://dotnetpools.com/Article/ArticleDetiail/?articleId=24&title=Ajax%20Login%20Example%20Using%20Jquery%20%20In%20Asp.net
John LiamirasPosted May 11, 2012, 8:20 AM
Hello Rahul, I try to log in but the proggram not connected in UserDetails page.When put to Log In Button all it does refresh the log in page
Abhimanyu K VatsaPosted Mar 14, 2012, 2:50 AM
Buddy, the project I have attached here is fully tested by many guys, i can't think that has any error. I'll recommend you to check the coding or come with the error msg in forum section here. Thanks.
Shrisha S BhatPosted Mar 14, 2012, 2:12 AM
When I execute the Default.aspx page on Visual Studio 2010 it gives me this error "This page contains the following errors: error on line 1 at column 2: StartTag: invalid element name Below is a rendering of the page up to the first error." How do I fix it?
DungxkPosted Nov 8, 2011, 4:14 AM
thanks very much
kumar yateenPosted Aug 25, 2011, 4:38 AM
which version of visual studio and sql is best and available free for a fresher... wants to create a simple project..
EggyPosted Mar 18, 2011, 3:25 PM
Hi, I would like to know why I entered the correct User Name and Password, but I still have the error message, "Invalid UserName and Passwor"? Thank you
shashika sameeraPosted Jan 31, 2011, 3:48 AM
Thank you for youre kind attention,still am not good in cording,can send an example how to set it in win forms, Thank you
shashika sameeraPosted Jan 30, 2011, 9:26 AM
Can you Explain that how can implement it in windows form
harsh desPosted Dec 13, 2010, 4:46 AM
i like the way u r teching good 1 dude