<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>Verifying TextBox Entries Against Values Stored in a Database</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
protected void Page_Load ( object src, EventArgs e ) {
if ( IsPostBack ) {
if ( Page.IsValid ) {
string query = "SELECT UserID from users WHERE UserEmail='" + Request.Form [ "UserEmail" ] + "' AND Password='" + Request.Form [ "Password" ] + "'";
OleDbConnection myConn = new OleDbConnection ( "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Server.MapPath ( "~/app_data/guests.mdb" ) );
OleDbCommand myCommand = new OleDbCommand ( query, myConn );
myConn.Open ( );
OleDbDataReader myReader = myCommand.ExecuteReader ( );
if ( myReader.Read ( ) ) {
string uid = myReader [ "UserID" ].ToString ( );
message.InnerHtml = "Hello, earthling no. " + uid;
}
else message.InnerHtml = "Sorry, no key no entry!";
myReader.Close ( );
myConn.Close ( );
}
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Verifying TextBox Entries Against Values Stored in a Database</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<table border=0 cellpadding=10 bgcolor="#bbccdd">
<col align="right">
<tr>
<td><b>User Email:</b></td>
<td><input id="UserEmail" runat="server" />
<asp:requiredfieldvalidator
controltovalidate="UserEmail"
errormessage="sender’s name cannot be blank. "
text="*" runat=server />
<asp:regularexpressionvalidator
controltovalidate="UserEmail"
validationexpression="^ [ \w- ] +@ [ \w- ] +\. ( com|net|org|edu|mil ) $"
errormessage="Please enter a valid e-mail address. "
display="none" runat=server /></td></tr>
<tr>
<td><b>Password:</b></td>
<td><input id="Password" type=password runat="server" />
<asp:requiredfieldvalidator
controltovalidate="Password"
errormessage="Password cannot be blank."
display="none" runat=server /></td></tr>
<tr>
<td colspan=2 align="center"><input type=submit value="Log In" runat="server" /></td></tr>
</table>
<asp:validationsummary runat="server"
displaymode="BulletList" />
<p id="message" runat="server"></p>
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>