Authenticate Login using an Array

The Login Page prompts the user for his/her username and password

Page 1 of 1

2 Replies - 4599 Views - Last Post: 23 February 2011 - 04:42 AM

#1 sigmafunk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-April 09

Authenticate Login using an Array

Posted 14 November 2010 - 11:28 PM

Brief description of what I have to do is:
The login page prompts the user for his/her username, password, and first and last name. If the username and password is invalid, the system will not allow access. The system will continue to request the login information. I also must be able to Delete a user, Add a user, Change or update the password and Display or show the array or records.

This is what I have for HTML:
<html> 

	<head> 
		<title>Password Policy</title>
			<script type = "text/javascript" src="autho.js">
		</script>
	</head>

	<body>
		<form name = "myform">
<p>
<center>

ENTER USER NAME:       <input type="text" name="username"  size=34 maxlength=10/><br/> 
ENTER PASSWORD:       <input type="password" name="pword" size=35 maxlength=10/><br/>
ENTER FIRST and LAST NAME:       <input type="text"  name="flname" size=22 maxlength=20/><br/>

<input type="button" value="Login" id="Submit" onclick="validate()"/>

<input type="button" value="Add user" id="Adduser" onclick="Adduser()"/>

<input type="button" value="Delete user" id="Deleteuser" onclick="Deleteuser()"/>

<input type="button" value="Show Data" id="Showdata" onclick="Showdata()"/>

<input type="button" value="Update password" id="Updatepass" onclick="Updatepass()"/>

<input type="button" value="Clear" id="doClear" onclick="doClear()"/>



</center>
</p>

		</form>
	</body> 
</html>




This is what I have for Javascript:
function validate() 
{
var un = document.myform.username.value;
var pw = document.myform.pword.value;
var flname = document.myform.flname.value;
var valid = false;
var invalid = true;

var flnameArray = ["Kaunda Hughes","Coniece Cookhorn"]
var unArray = ["Khughes7", "Cookiecane"];  
var pwArray = ["Password1", "Password2"];  

for (var i=0; i <unArray.length; i++) 
{
if ((un == unArray[i]) && (pw == pwArray[i]) && (flname == flnameArray[i])) 
{
valid = true;

}
}

if (valid) 
{
alert ("Access is Granted");

return false;
}

else

if (invalid) 
{
alert ("Access Denied");
return true;
}
}

function doClear()
{
document.getElementById("username").value="";
document.getElementById("pword").value="";
document.getElementById("flname").value="";
}

function Adduser()
{
alert("Add person ");
un.push(document.getElementById("username").value);
pw.push(document.getElementById("pword").value);
flname.push(document.getElementById("flname").value);
alert("Name added was: " + document.getElementById("username").value);
}

function Deleteuser()
{
alert("Delete person ");
un.pop(document.getElementById("username").value);
pw.pop(document.getElementById("pword").value);
flname.pop(document.getElementById("flname").value);
alert("Name deleteded was: " + document.getElementById("username").value);
}

function Updatepass()
{
alert("Changing password ");
var t1=pw.splice(pwArray[i],pwArray[i],"Password5","Password6");
document.write(pw.join(" <br> ")); 
alert("Password changed ");
}

function Showdata()
{
alert("Compiling data ");
document.write(un.toString());
document.write(pw.toString());
document.write(flname.toString());
alert("Finished compiling data ");
}




Any help would be most appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Authenticate Login using an Array

#2 MrLuke187  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 81
  • View blog
  • Posts: 237
  • Joined: 09-July 10

Re: Authenticate Login using an Array

Posted 15 November 2010 - 03:50 AM

I don't think that Javascript is the best way of doing this. Just imagine, that anyone can open and show your "autho.js"-File and read the Passwords from it.

PHP and MySQL would be a better choice.

Greetings: Luke
Was This Post Helpful? 1
  • +
  • -

#3 Guest_SaeedSes*


Reputation:

Re: Authenticate Login using an Array

Posted 23 February 2011 - 04:42 AM

View PostMrLuke187, on 15 November 2010 - 03:50 AM, said:

I don't think that Javascript is the best way of doing this. Just imagine, that anyone can open and show your "autho.js"-File and read the Passwords from it.

PHP and MySQL would be a better choice.

Greetings: Luke


I have altered your code to fix some issues in it. and it is working fine for me... it saves usernames and passwords and then authenticates properly.Attached File  xpage.html (3.96K)
Number of downloads: 172

Cheers,
Saeed.
saeedses@gmail.com
Was This Post Helpful? 0

Page 1 of 1