Solved

Data Access Page - create Login Page

Posted on 2004-04-13
11
457 Views
Last Modified: 2008-03-03
Microsoft Access Solutions and Articles
   
 Question Title: Data Access Page - Create Login
Author: nibirkhan
Points: 500
Date: 04/12/2004 04:40PM EDT
 


I need to create a login page with DAP, I have four fields on my table(TBL_EmpID_Passw) below:

EmpID         PermiStatus          Dept             Password
---------       -------------        -------------         ------------
145                   Admin               HR                abcd
555                   User                  ENG             ahski
345                   Foreman            WKS             iojllloo9

Here is what I have done till now:
----------------------------------------
I created two unbound field on the Page, one is a drop down list box “SelectID” and another is “EnterPassw”, then I have inserted the bound fields from the Tables above and made them Hidden. As soon as an user select his EmpID from the Drop down list box, it finds relative records to the hidden fields (EmpID, PermiStatus, Dept, Password). I have done till this part, it works fine.


Now what I need to do is to have a button on the page “OK” and “Cancel”
------------------------------------------------------------------------------------------
1.If the user hit “Ok” after entering EmpID and Passw, my button should load another page based  
  on the user’s “PermiStatus”

2.If the “PermiStatus” is “Admin” it should load “Admin.htm” page which I have created already
   and staying on my local server http://localhost/Admin.htm else if the “PermiStatus” is “User” it
   should load “User.htm” page and if “PermiStatus” is “Foreman” it should load “Foreman.htm”  
   page

3.I also need to carry those fields value(EmpID, Dept) from the log on page to the “Admin.htm”,
  User.htm or Foreman.htm to show a msg (You are logged on as: “EmpID”)

4.  Hitting cancel button will close the login page

I need the script/code for the “OK” and “Cancel” buttons onclick event, and how will I transfer those value to the linked page? If anyone could help will be highly appreciated..

Thanks-

Nibirkhan
 
 
I have the .mde file and the forms done, if you want the .mbe file please send me an email.
0
Comment
Question by:nibirkhan
  • 5
  • 5
11 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 10816746
Holding the Password in hidden fields is visible for anyone who wants to lookup.
It has to be checked on server side, so you need a web server scripting language.
What type is your web server and what scripting language do you want to use?
0
 
LVL 12

Accepted Solution

by:
lil_puffball earned 500 total points
ID: 10818061
Here is an example:
------------------------------------
<script>
var data=new Array();
  data[145]=new Array("Admin","HR","abcd");
  data[555]=new Array("User","ENG","ahski");
  data[345]=new Array("Foreman","WKS","iojllloo9");

function loadPage(){
  var sel=document.forms[0].EmpID;
  var EmpID=sel.options[sel.selectedIndex].text;
  location.href=data[EmpID][0]+".htm?EmpID="+EmpID+"&Dept="+data[EmpID][1];
}
</script>

<form>
<select name=EmpID>
<option>145
<option>555
<option>345
</select>

<input type=button value="OK" onclick="loadPage();">
<input type=button value="Cancel" onclick="self.close();">
</form>
------------------------------------------

In this case the data transferred to the new page will be stored in the url, e.g.

Admin.htm?EmpID=145&Dept=HR

If you don't want to show it in the URL, you will have to use a server side language. This also lets the user see the passwords, like Zvonko pointed out.
0
 
LVL 2

Author Comment

by:nibirkhan
ID: 10825856
Hi,

Thanks for your post. Well I am using Access db on my server and my server is a web server, I really don't know much about the server but my Data Access Page runs fine over the HTTP on my local office intranet.

Could you please tell me details?

Here is the link of my file, all I want the exact functionality I have on my forms right now, the password is "pass"

http://jupiter.clarion.edu/~s_mskhan/LogIn.zip

Thanks
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10829582
So...the user enters their EmpID and their password, and then you log them in based on the information in the database? I'm still pretty confused here...
0
 
LVL 2

Author Comment

by:nibirkhan
ID: 10829848
yeap you are right,....

IT swaps the data from the table after you choose the EmpID from the combo box and then it compares, if a match then it lets you log in else it gives error!!

If you dig through my code you will see the fucntion...

--What do you think???

--Nibirkhan
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Expert Comment

by:lil_puffball
ID: 10851008
Sorry for the delay, I was busy the past few days...

Anyways, I just wrote up a script in ASP. Please go here: http://www34.brinkster.com/lilpuffball/ee/loginPage.asp

Please tell me if there are things I misunderstood or things I need to add/remove.
I will post the code if you like the way it is now. :)
0
 
LVL 2

Author Comment

by:nibirkhan
ID: 10854807
Thanks a lot for your efforts. Yeap, I wanted exactly that way.

There were some debuging error came, when I was trying to view the page. But the functionality looks same as mine, only thing is that when you enter the database, it will load the Menu page based on the "Status", if you are Admin then it will load AdminMenu.htm, if you are Foreman, it will load ForemanMenu.htm ..so on...

Please, give me details how to build as I am new on DAP or ASP...
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10854988
0
 
LVL 2

Author Comment

by:nibirkhan
ID: 10989777
yes, it looks like it...

How did you do it? Please let me know, My office server wasn't helping me enough so, I quite writing on DAp but I am writing them on VB.NET so that it can be paltform independent...

If you can have any help on VB.NET let me know...I am giving you the points

thanks
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10990479
Thank you for the points and the A. :)

Here is the code for all the pages (you also need 2 arrow images, I called mine arrow.gif and arrow-down.gif):
(I think these are all the pages you need, but I could be missing some, please let me know if I am)

==========================================
loginPage.htm
==========================================
<script>
var page=new Array();
  page["Administrator"]="Admin.asp";
  page["Foreman"]="Foreman.asp";
  page["User"]="User.asp";

function logIn(id,name,permiStatus){
document.data.action=page[permiStatus];
document.data.id.value=id;
document.data.name.value=name;
document.data.submit();
}
</script>

<button onclick="window.open('logIn.asp','','height=400,width=600,status=no,location=no,menubar=no,toolbar=0,scroll=no,resizable=no');">
Click to Log In
</button>

<form method=post action="loginPage.htm" name=data>
<input type=hidden name=id>
<input type=hidden name=name>
</form>

==========================================
logIn.asp
==========================================
<%
'Initialize database and records
Dim conn,rs,sql
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\lilpuffball\db\LogIn.mdb"))
Set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from DCC_TBL_EmpIDPassW"
rs.Open sql,conn
%>

<style>
.black{cursor:default;border-bottom-style:solid;border-bottom-width:1px;border-bottom-color:black;border-right-style:solid;border-right-width:1px;border-right-color:black;color:#000099;font-weight:bold;font-size:13px;font-family:arial;}
.grey{cursor:default;border-right-style:solid;border-right-width:1px;border-right-color:#cccccc;color:#000099;font-weight:bold;font-size:13px;font-family:arial;}
.none{cursor:default;color:#000099;font-weight:bold;font-size:13px;font-family:arial;}
</style>

<script>
var prev=null,hide=false,selectDiv,obj;
function hili(row){
  for(i=0;i<row.childNodes.length;i++){
    row.childNodes[i].bgColor="#000066";
    row.childNodes[i].style.color="white";
  }
  if(prev){
     for(i=0;i<prev.childNodes.length;i++){
      prev.childNodes[i].bgColor="white";
      prev.childNodes[i].style.color="#000099";
    }
  }
  prev=row;
}
function setID(row){
  obj.value=row.firstChild.innerHTML;
  selectDiv.style.display='none';
  hide=false;
  document.forms[0].password.disabled=false;
  document.forms[0].password.style.backgroundColor='white';
}
function checkData(){
  var tbl=selectDiv.firstChild.firstChild,rowNum;
  for(i=1;i<tbl.childNodes.length;i++){
    if(tbl.childNodes[i].firstChild.innerHTML==obj.value){rowNum=i;break;}
  }
  if(!rowNum){alert("Invalid ID!");return;}
  document.frames["checkPW"].document.forms[0].pw.value=document.forms[0].password.value;
  document.frames["checkPW"].document.forms[0].id.value=obj.value;
  document.frames["checkPW"].document.forms[0].name.value=tbl.childNodes[rowNum].childNodes[1].innerHTML;
  document.frames["checkPW"].document.forms[0].permiStatus.value=tbl.childNodes[rowNum].childNodes[2].innerHTML;
  document.frames["checkPW"].document.forms[0].submit();
}
function init(){
  selectDiv=document.all?document.all("selectDiv"):document.getElementById("selectDiv");
  obj=document.forms[0].select;
  var top=obj.offsetTop,left=obj.offsetLeft,h=obj.offsetHeight;
  while(obj.offsetParent){
    top+=obj.offsetTop;
    left+=obj.offsetLeft;
    obj=obj.offsetParent;
  }
  selectDiv.style.top=top+h;
  selectDiv.style.left=left;
  selectDiv.style.width=selectDiv.firstChild.offsetWidth+20;
  selectDiv.style.display='none';
  obj=document.forms[0].select;
}
</script>

<title>Welcome to Database Command Center</title>
<body bgcolor=#ffffdd style="text-align:center;cursor:default;" onload="init();" onclick="if(hide){selectDiv.style.display='none';hide=false;}">
<form>

<iframe src="checkPW.asp" name=checkPW style="display:none;"></iframe>

<span style='height:25;width:150;color:white;background-color:red;font-family:arial;font-size:16px;padding:2px;'>
<b>Login Page</b>
</span>

<p>

<span style='height:60;width:100%;border-style:groove;border-width:2px;font-family:arial;font-size:14px;text-align:left;'>
<table border=0 style='font-family:arial;font-size:13px;font-weight:bold;'>
<tr><td align=right><font color=#000099>Select Your Employee ID: </font></td><td>
<input type=text name=select onkeyup="this.form.enterDatabase.disabled=(this.value=='')||(this.form.password.value=='');" style="width:100;background-color:white;color:#000099;font-weight:bold;font-size:13px;font-family:arial;"
><img src=arrow.gif onclick="if(!hide){selectDiv.style.display='inline';setTimeout('hide=true;',1);}" onmousedown="this.src='arrow-down.gif';" onmouseup="this.src='arrow.gif';" onmouseout="this.src='arrow.gif';">
</td></tr>
<tr><td align=right><font color=black>Password:</font></td>
<td><input type=password name=password onkeyup="this.form.enterDatabase.disabled=(this.value=='')||(this.form.select.value=='');" style="width:100;font-size:12px;background-color:#cccccc;" disabled></td></tr>
</table>
</span>

<p>

<span style='width:100%;'>
<table border=0 width=100%><tr>
<td><input type=button value="Exit Database" onclick="self.close();" style="font-family:arial;background-color:buttonface;color:red;font-weight:bold;font-size:12px;"></td>
<td align=right>
<input type=button name=enterDatabase value="Enter Database" onclick="if(this.form.password.value==''||this.form.select.value==''){alert('ID and Password cannot be empty.');this.disabled=true;}else{checkData();}" style="font-family:arial;background-color:buttonface;color:blue;font-weight:bold;font-size:12px;" disabled></td>
</tr></table>
</span>

<div id=selectDiv style="position:absolute;overflow:auto;top:-500px;height:100px;width:auto;">
<table style="width:100%;border-style:solid;border-width:1px;border-color:black;background-color:white;" border=0 cellspacing=0 cellpadding=2>
<tr>
<td class=black>Emp_ID</td>
<td class=black>Emp_Name</td>
<td class=black>Permission Status</td>
<td class=black style="border-right:none;">Dept_ID</td>
</tr>

<%
Do while not rs.EOF
%>
<tr onmouseover="hili(this);" onclick="setID(this);"><td class=grey><%=rs("Emp_ID")%></td><td class=grey><%=rs("Emp_Name")%></td><td class=grey><%=rs("PermissionStatus")%></td><td class=none><%=rs("Dept_ID")%></td></tr>
<%
rs.MoveNext
Loop
%>
</table>
</div>
<%
'Close everything
rs.Close
Set rs=Nothing
Set conn=Nothing
%>
</form></body>

==========================================
checkPW.asp
==========================================
<form method=post action="checkPW.asp">
<input type=hidden name=id>
<input type=hidden name=pw>
<input type=hidden name=name>
<input type=hidden name=permiStatus>
</form>

<%
Dim pw,id,name,permiStatus
pw=Request.Form("pw")
id=Request.Form("id")
name=Request.Form("name")
permiStatus=Request.Form("permiStatus")


If pw<>"" Then
  'Initialize database and records
  Dim conn,rs,sql
  Set conn=Server.CreateObject("ADODB.Connection")
  conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\lilpuffball\db\LogIn.mdb"))
  Set rs=Server.CreateObject("ADODB.Recordset")
  sql="select * from DCC_TBL_EmpIDPassW where Emp_ID='" & id & "'"
  rs.Open sql,conn

  response.write("<script>")
  'if invalid
  If rs("Emp_Passw")<>pw Then
    response.write("alert('Error: ID and Password do not match.');")
  'if valid
  Else
    response.write("parent.opener.logIn('" & id & "','" & name & "','" & permiStatus & "');parent.close();")
  End If
  response.write("</script>")

  'Close everything
  rs.Close
  Set rs=Nothing
  Set conn=Nothing
End If
%>

==========================================
checkPW.asp
==========================================


==========================================
Admin.asp (All other pages, like foreman.htm are similar)
==========================================
<%
dim name,id
name=request.form("name")
id=request.form("id")
%>

This is the Administrator Page.<p>

You are logged in as: <%=name%>. Your ID is <%=id%>.
0
 
LVL 2

Author Comment

by:nibirkhan
ID: 10998778
thanks a lot..i'll check them on the weekend and let you know..

--Khan
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now