These search terms have been highlighted: login page in asp.net (Clear)
1 2 > Last »
• Paladine
Master Poster
Simple ASP.NET Login Page using C# ( ASP.NET 1.0 & 1.1 ONLY!!! NOT 2.0)
This is just a small demonstration to show how easy one can "port" the code from my
previous tutorials ( Updated: Simple ASP.Net Login Page & ASP.Net Login
Page with SQL & ASP.Net Registration Page ) over to another programming
language in the .NET environment. In this example I chose to use C#.
So for all considerations this tutorial is an exact duplicate of the Updated: Simple
ASP.NET Login Page using VB.NET that I did previously, but using SQL instead of
Access for the DB
- Include any control validation you feel necessary. Software Development Forum
(Toggle Plain Text) Help with Code Tags C# News Stories (2)
display="None"></asp:requiredfieldvalidator></td>
</tr>
<tr>
<td><b>Password: </b>
</td>
<td><asp:textbox id="txtPassword" runat="server"
width="160px"
textmode="Password"></asp:textbox><asp:requiredfieldvalidator
id="rvPasswordValidator" runat="server" controltovalidate="txtPassword"
errormessage="Empty Passwords not accepted"
display="None"></asp:requiredfieldvalidator></td>
</tr>
<tr>
<td align="center" colspan="2"><asp:button
id="cmdSubmit" runat="server" text="Submit"
borderstyle="Solid"></asp:button></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table id="messageDisplay">
<tr>
<td><asp:validationsummary
id="Validationsummary1" runat="server" width="472px"
displaymode="BulletList"></asp:validationsummary></td>
</tr>
</table>
<!--<asp:hyperlink id="hl_Register"
runat="server" navigateurl="Register.aspx" font-size="X-Small"
height="8px" width="209px" font-names="MS
Reference Sans Serif">New User?...Register Here!</asp:hyperlink>-->
</td>
</tr>
</table>
</form>
<asp:label id="lblMessage" runat="server" width="288px" font-
bold="True" font-italic="True"
font-size="Medium" forecolor="#C00000"></asp:label>
<asp:label id="lblMessage2" runat="server" width="288px" font-
bold="True" font-italic="True"
font-size="Medium" forecolor="#C00000"></asp:label>
<!-- ||||| End of Form ||||| -->
</body>
</html>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
// <summmary>
// What has been added for Login Page
// for this application to function
// </summary>
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;
namespace NorthCSharp
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.RequiredFieldValidator
rvUserValidator;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.RequiredFieldValidator
rvPasswordValidator;
protected System.Web.UI.WebControls.Button cmdSubmit;
protected System.Web.UI.WebControls.ValidationSummary
Validationsummary1;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Label lblMessage2;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cmdSubmit.Click += new System.EventHandler
(this.cmdSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
private bool DBConnection(string txtUser, string txtPass)
{
SqlConnection myConn = new SqlConnection
(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCmd = new SqlCommand("sp_ValidateUser", myConn);
myCmd.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1;
SqlParameter objParam2;
SqlParameter returnParam;
objParam1.Direction = ParameterDirection.Input;
objParam2.Direction = ParameterDirection.Input;
returnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = txtUser;
objParam2.Value = txtPass;
try
{
if (myConn.State.Equals(ConnectionState.Closed))
{
myConn.Open();
myCmd.ExecuteNonQuery();
}
if ((int)returnParam.Value < 1)
{
lblMessage.Text = "Invalid Login !";
return false;
}
else
{
myConn.Close();
return true;
}
}
catch (Exception ex)
{
lblMessage2.Text = ex + "Error Connecting to the database";
return false;
}
}
}
}
Web.Config
(Toggle Plain Text) Help with Code Tags
]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="strConn" value="Network Library=DBMSSOCN;Data
Source=192.168.0.100,1433;database=Northwind;User id=;Password=;"/>
</appSettings>
<system.web>
Happy Coding!
•
Ads by Google
C Source Code
Be a Software Professional by Choosing a course @ MingleBox.com
MingleBox.com/C_Courses
•
C++
ForumNokia Developer Conference. Learn from Mobile Experts.KnowMore!
www.Nokiadevcon.in
LogExpert
Windows tail program and logfile analysis for free. www.log-expert.de/
•
BeeNarak
Newbie Poster
Offline
Solved Threads: 0
0 #2
Hi Paladine,
I have to modify the c# code from the SQL server example to work for AccessDB
but it's doesn't work. Please see my code as below;
BeeNarak
• Paladine
Master Poster
Offline
Solved Threads: 26
Ok What error are you getting? Saying it doesn't work provides me no indication as to
what the problem is.
Why are you converting an int value to a string and comparing it to a string int?
code in question:
1. (string)objReader.GetValue(0) != "1"
Should be
1. objReader.GetValue(0) = 0
I also may need to see what your stored procedure code looks like.
•
BeeNarak
Newbie Poster
Offline
Solved Threads: 0
0 #4
Hi Paladine,
Thank you so much for your explanations.
Why are you converting an int value to a string and comparing it to a string int?
- Sorry i'm poor experience about c# programing so some time i've got a mistake. :s
my code as below;
Last edited by Paladine; Jul 14th, 2005 at 3:06 am. Reason: Adding code blocks
• Paladine
Master Poster
Offline
Solved Threads: 26
Jul 12th, 2005 0 #5
No worries...
It should be (and please review the code you copied from - i.e the tutorial)
1. (int)objReader.GetValue(0) = 0
•
BeeNarak
Newbie Poster
Offline
Solved Threads: 0
0 #6
Hi Paladine,
Thanks for your explanations. I've to change as your idea from "(objReader.GetValue(0) =
0)" to "(int)objReader.GetValue(0) = 0" as your idea it's still got error
'( Login .WebForm1.DBConnection(string, string)'.
I just tried your vb.net code it's work! and then i was convert vb.net to c# code it's still
have got error as above. What's wrong?
regards,
Bee
•
BeeNarak
Newbie Poster
Offline
Solved Threads: 0
0 #7
I've got a full error when i change code "( Login .WebForm1.DBConnection(string,
string): not all code paths return a value".
Do you have any idea?
Thanks,
Bee
•
BeeNarak
Newbie Poster
Offline
Posts: 8
Reputation:
•
Join Date: Jul 2005
Solved Threads: 0
Re: Simple ASP.Net Login Page using C#
Jul 13th, 2005 0 #8
Hi Paladine,
Cheers,
Bee
• Paladine
Master Poster
Offline
Solved Threads: 26
yes, but it should be return True if login is Successful, and False if not
1. if (objReader.GetValue(0) = 0)
2. {
3. lblMessage.Text = "Invalid Login !";
4. //return false;
5. }
•
Ads by Google
Solved Threads: 0
0 #10
ive tried using this. ive used it once before with your vb.net and it worked pefectly. im
now learning c# and when i go to put this together the web.config keeps throwing this
error:
Parser Error Message: The data at the root level is invalid. Line 1, position 1.
Source Error:
it points to the using system directive. anyone knw what would cause this?
1 2 > Last »
• Message:
•
•• Post Reply
••
Transportation Design - AutoCAD Civil 3D Show Printable Version
Design Road Projects 75% Faster with Automatic
Documentation Updates!
Similar Threads
Virtualization Solutions
Optimize, Simplify, & Save Today. Learn About Updated : Simple ASP.Net Login
Page (ASP.NET)
Microsoft Solutions.
Simple ASP.Net Login Page (Using
Microsoft SQL Server® 2008 - Free Trial VB.Net) (ASP.NET)
.net access algorithm angle array barchart bitmap box broadcast c# capturing check checkbox client combobox control conversion convert csharp custom
database datagrid datagridview dataset datetime dbconnection degrees delegate design development disappear draganddrop drawing encryption enum event
excel file firefox form format forms function gdi+ httpwebrequest image index input install java label leak libraries list listbox mandelbrot math monodevelop
mouseclick msword mysql operator path pause photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox round server
sleep socket sql statistics stream string table tcpclientchannel text textbox thread time timer update usercontrol validation virtualization visualbasic visualstudio