Last post Oct 02, 2013 10:24 AM by Dcw87
Oct 02, 2013 07:48 AM|Dcw87|LINK
Hi Guys :)
I'm sure this is a relatively simple task but it's beyond my abitilies at the moment!
All I'm trying to do is create a single page of a website called Admin.aspx (This will have graphs, stats etc.) password protected. So, if i loaded the page as a user, i could open up the home page, and the others, but as soon as i click on Admin, i want
it to prompt me for a password.
Now, this doesn't need to be secure as its only used by a handful of people and its an internal system, I don't want to use a database, just something quicky and dirty :)
If anyone could help (In C#), that would be great :)
Thanks in advance!
Oct 02, 2013 07:58 AM|smirnov|LINK
Move all existing content of that page to a panel1. Add another panel2 which will include password field and submit button.
On the page_load check for Session["Admin"]
If it is null make panel1 invisible and display panel2 with the password field and submit button
On submit of the password submit button check if password was "passw0rd" and if true, add it to Session["Admin"] and make panel2 invisible and panel1 visible
It all can be done without Session["Admin"] but using session will help to avoid entering password every time user needs to go to admin.aspx.
Oct 02, 2013 08:07 AM|Dcw87|LINK
Wow, look at that, I solved it :)
Just in case anyone else stumbles onto this, here's how i did (VERY dirty and insecure, but perfect for what i need it for).
In the page you want to protect, insert the below in your aspx page
<div id="login_form" runat="server">
Please enter the username & password to continue to the admin page:</p>
<br />Username:<br />
<asp:TextBox ID="username" runat="server"></asp:TextBox>
<asp:TextBox ID="password" TextMode="Password" runat="server"></asp:TextBox>
<asp:Button ID="Login" OnClick="Login_Click" runat="server" Text="Login" />
<div id="rest_of_site" runat="server" visible="false" >
<p>This page shows secure stuff</p>
Insert random secure things......
Double click on the login button that appears now in design view, and enter this in the c# page:
protected void Login_Click(object sender, EventArgs e)
if ((username.Text == "Username") & (password.Text == "Password"))
login_form.Visible = false;
rest_of_site.Visible = true;
login_form.Visible = true;
rest_of_site.Visible = false;
Hopefully this helps someone
Oct 02, 2013 10:24 AM|Dcw87|LINK
Managed to get it working :)