Hi All, am a new web developer in ASP.NET, am developing an application that involves user Interface. In my application am assuming that there is already a database which consists of user profile e.g Username, password, Firstname etc., so I created a database and I manually put in values. the reason why am doing this is that there is already an existing application interface which am not going to deal with.
Also, I created a login button with username and password and I want the application to check if username and password are valid before allowing the User to log in. I used two sqldatasource control for the username and password, in the Where tab I clicked on Control e.g userrname and ControlId e.g userTxt(this is the text box).The application is working if the user enter correct username and password but for the other way is not really working. dnt knw where the problem is.
How can I encrypt my the password and also how can I make the user to change their password so that it can reflect in the existing database. here is my code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoginMenu.aspx.cs" Inherits="LoginMenu" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
text-align: center;
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<p style="margin-left: 320px">
<asp:Label ID="UserLb" runat="server" Text="UserName"></asp:Label>
<asp:TextBox ID="UserTxt" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredUserTxt" runat="server"
ControlToValidate="UserTxt" ErrorMessage="Required"></asp:RequiredFieldValidator>
<asp:Label ID="Label1" runat="server" Text="Enter correct name" Visible="False"></asp:Label>
</p>
<p style="margin-left: 320px">
<asp:Label ID="PasswrdLb" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="PasswrdTxt" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredPasswrdTxt" runat="server"
ControlToValidate="PasswrdTxt" ErrorMessage="Required"></asp:RequiredFieldValidator>
<asp:Label ID="Label2" runat="server" Text="Enter Correct Password"
Visible="False"></asp:Label>
</p>
<asp:Button ID="LogOnBtn" runat="server" Height="26px" onclick="LogOnBtn_Click"
Text="LogOn" />
</p>
<p style="margin-left: 320px">
Do You want to Change Your Password?
<asp:HyperLink ID="ChangePasswrdHyp" runat="server"
NavigateUrl="~/ChangePassword.aspx">Click Here</asp:HyperLink>
<p style="margin-left: 320px">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Users] WHERE ([UserName] = @UserName)">
<SelectParameters>
<asp:ControlParameter ControlID="UserTxt" Name="UserName" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</p>
<p style="margin-left: 320px">
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Users] WHERE ([Password] = @Password)">
<SelectParameters>
<asp:ControlParameter ControlID="PasswrdTxt" Name="Password"
PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</p>
</ContentTemplate>
<asp:Label ID="UserLb0" runat="server" Text="UserName"></asp:Label>
<asp:TextBox ID="UserTxt0" runat="server"></asp:TextBox>
<asp:Label ID="PasswrdLb0" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="PasswrdTxt0" runat="server"></asp:TextBox>
<asp:CheckBox ID="CheckBox2" runat="server" />
<asp:Button ID="LogOnBtn0" runat="server" Height="26px"
onclick="LogOnBtn_Click" Text="LogOn" />
To Change Your Password? <asp:HyperLink ID="HyperLink2" runat="server">HyperLink</asp:HyperLink>
</p>
</form>
</body>
</html>
protected void LogOnBtn_Click(object sender, EventArgs e)
{
DataView user_reader = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
DataView password_reader = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
if (user_reader.Table.Rows.Count == 0)
this.Label1.Visible = true;
else
{
if (password_reader.Table.Rows.Count == 0)
this.Label2.Visible = true;
else
Response.Redirect("ChangePassword.aspx");
}
}
}
cheers