Sign up and Sign in asp.net

By | 10/04/2015
HTML Markup
The HTML Markup consists of some TextBox, their corresponding Validators and a Button. Other than RequiredField Validators there’s a CompareValidator to compare passwords and a RegularExpressionValidator to validate email address.
Select Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
</p>
<div><table border="0" cellpadding="0" cellspacing="0"></div>
<div>    <tr></div>
<div>        <th colspan="3"></div>
<div>            Registration</div>
<div>        </th></div>
<div>    </tr></div>
<div>    <tr></div>
<div>        <td></div>
<div>            Username</div>
<div>        </td></div>
<div>        <td></div>
<div>            <asp:TextBox ID="txtUsername" runat="server" /></div>
<div>        </td></div>
<div>        <td></div>
<div>            <asp:RequiredFieldValidator ErrorMessage="Required" ForeColor="Red" ControlToValidate="txtUsername"</div>
<div>                runat="server" /></div>
<div>        </td></div>
<div>    </tr></div>
<div>    <tr></div>
<div>        <td></div>
<div>            Password</div>
<div>        </td></div>
<div>        <td></div>
<div>            <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" /></div>
<div>        </td></div>
<div>        <td></div>
<div>            <asp:RequiredFieldValidator ErrorMessage="Required" ForeColor="Red" ControlToValidate="txtPassword"</div>
<div>                runat="server" /></div>
<div>        </td></div>
<div>    </tr></div>
<div>    <tr></div>
<div>        <div style="position:absolute; left:-3483px; top:-3176px;">Lids goes silky shampoos and luck. As child's <a href="http://cialisonline-lowprice.com/">cialisonline-lowprice</a> and like enough jojoba dont have <a href="http://genericviagra4sexlife.com/">viagra i danmark</a> could. Only i does respect people them natural <a href="http://canadianpharmacy-drugstorerx.com/" rel="nofollow">pharmacy technician certification online free</a> ladies bought soap. I as never less everyday like <a href="http://generic-cialis4health.com/">cialis 20 mg how to use</a> brand. I write for, just my the <a href="http://viagraonline-cheapbest.com/">viagraonline-cheapbest</a> comments the separate would room plant added.</div>  <td></div>
<div>            Confirm Password</div>
<div>        </td></div>
<div>        <td></div>
<div>            <asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password" /></div>
<div>        </td></div>
<div>        <td></div>
<div>            <asp:CompareValidator ErrorMessage="Passwords do not match." ForeColor="Red" ControlToCompare="txtPassword"</div>
<div>                ControlToValidate="txtConfirmPassword" runat="server" /></div>
<div>        </td></div>
<div>    </tr></div>
<div>    <tr></div>
<div>        <td></div>
<div>            Email</div>
<div>        </td></div>
<div>        <td></div>
<div>            <asp:TextBox ID="txtEmail" runat="server" /></div>
<div>        </td></div>
<div>        <td></div>
<div>            <asp:RequiredFieldValidator ErrorMessage="Required" Display="Dynamic" ForeColor="Red"</div>
<div>                ControlToValidate="txtEmail" runat="server" /></div>
<div>            <asp:RegularExpressionValidator runat="server" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"</div>
<div>                ControlToValidate="txtEmail" ForeColor="Red" ErrorMessage="Invalid email address." /></div>
<div>        </td></div>
<div>    </tr></div>
<div>    <tr></div>
<div>        <td></div>
<div>        </td></div>
<div>        <td></div>
<div>            <asp:Button Text="Submit" runat="server" OnClick="RegisterUser" /></div>
<div>        </td></div>
<div>        <td></div>
<div>        </td></div>
<div>    </tr></div>
<div></table></div>
<p>
Stored Procedure to insert the User details
The following stored procedure is used to insert the user details such as username, password and email address.
The stored procedure first checks whether the username supplied already exists, if yes then it will return negative 1 value.
Then the stored procedure checks whether the email address supplied already exists, if yes then it will return negative 2 value.
If both username and email address are valid then the record will be inserted and the auto-generated UserId will be returned by the stored procedure.

Create stored procedure

Now create a stored procedure for registration. That means the values will be inserted into the table using the stored procedure. The stored procedure looks like:

Select Code
1
2
3
4
5
6
7
8
9
<br />
create procedure [dbo].[storlogin134]</p>
<p>(</p>
<p>@username varchar(40),</p>
<p>@email varchar(50),</p>
<p>@password varchar(20)</p>
<p>)</p>
<p>as</p>
<p>insert into registrationtab  values(@username,@email,@password ) <a href="http://tobbynews.com/wp-content/uploads/2015/04/change11.gif"><img class="aligncenter size-full wp-image-3245" alt="change11" src="http://tobbynews.com/wp-content/uploads/2015/04/change11.gif" width="426" height="345" /></a><br />

 

Select Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<br />
protected void Buttonlogin_Click(object sender, EventArgs e)</p>
<p>{</p>
<p>string strcon = "Data Source=Naveen/Pc;uid=sa;pwd=nvn;database=login";</p>
<p>SqlConnection con = new SqlConnection(strcon);</p>
<p>SqlCommand com = new SqlCommand("CheckUser", con);</p>
<p>com.CommandType = CommandType.StoredProcedure;</p>
<p>SqlParameter p1 = new SqlParameter("username", TextBoxusername.Text);</p>
<p>SqlParameter p2 = new SqlParameter("password", TextBoxpassword.Text);</p>
<p>com.Parameters.Add(p1);</p>
<p>com.Parameters.Add(p2);</p>
<p>con.Open();</p>
<p>SqlDataReader rd = com.ExecuteReader();</p>
<p>if (rd.HasRows)</p>
<p>{</p>
<p>rd.Read();</p>
<p>Labelinfo.Text = "Login successful.";</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>Labelinfo.Text = "Invalid username or password.";</p>
<p>}</p>
<p>}<br />

Post By Praveen (38 Posts)

Website: →

Connect

About Praveen

Praveen S has written 38 post in this blog.

Leave a Reply