Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy JavaScript Forms with Database Authentification help!

    *** I cant seem to get this code to work properly. I want the user to input a name and password then have the Authentification function check the database for usernames and passwords. this is how I was told to set it up but my professor said my logic is wrong. so please help! its been frustrating me for hours ***

    Code:
    <body>
    <script language="javascript">
    //  database goes here
    var username = new Array(3);
    username[0]="mary";
    username[1]="john";
    username[2]="kevin";
    var password = new Array(3);
    password[0]="poppins";
    password[1]="doe";
    password[2]="poppins";
    
    function Authenticate()
    {
    	// read the values from the form in the following variables
    	var name = document.getElementById("username").value; 	var pass = document.getElementById("password").value; 
    	var j;
    	//check the username and password against our database
    	for(i = 0; i < 3; i++)
    	{
    		if(name == username[i])
    		{
    			j = 1;
    		}
    		else if(pass == password[i])
    		{
    			j = 1;
    		}
    		else
    		{
    			j = 0;
    		}			
    		// output the appropriate message in the output Text Box.
    	}
    	if(j = 1)
    	{
    	document.getElementById("output").value = "correct login information";
    	}
    	else if(j = 0)
    	{
    	document.getElementById("output").value = "incorrect login information";
    	}
    }
    </script>
    <form name="form1">
     Username : <input name="username" type="text"><br><br>
     Password : <input name="password" type="password"><br><br>
     <input type="button" value="submit" onClick="Authenticate();"><br><br>
     
     Output   : <input name="output" type="text">
     
    </form>
    Last edited by Legit_Pig; 10-16-2009 at 08:40 PM.

  • #2
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is just a simple code my professor assigned for the lab. I just cant seem to get it to work. other students in the class have been able to

  • #3
    New Coder
    Join Date
    Aug 2009
    Posts
    94
    Thanks
    0
    Thanked 16 Times in 16 Posts
    Code:
    <html>
    	<HEAD>
    			<script language="javascript">
    			//  database goes here
    			var username = new Array(3);
    			username[0]="mary";
    			username[1]="john";
    			username[2]="kevin";
    			var password = new Array(3);
    			password[0]="poppins";
    			password[1]="doe";
    			password[2]="poppins";
    
    			function Authenticate()
    			{
    				// read the values from the form in the following variables
    									
    				var name = document.getElementById("username").value; 	var pass = document.getElementById("password").value; 
    				
    				if(name == "" || pass == ""){
    					document.getElementById("output").innerHTML = "Enter both username and password"
    					return;
    				}
    				
    				var j;
    
    				//check the username and password against our database
    				for(i = 0; i < 3; i++)
    				{
    					if(name == username[i] && pass == password[i])
    					{
    						j = 1;
    						break;
    					}
    					else
    					{
    						j = 0;
    					}			
    					// output the appropriate message in the output Text Box.
    				}
    			
    			
    				if(j == 1)
    				{
    					document.getElementById("output").innerHTML = "correct login information";
    				}
    				else if(j == 0)
    				{
    					document.getElementById("output").innerHTML = "incorrect login information";
    				}
    			}
    		</script>
    	</HEAD>
    
    
    	<body>
    
    		<form name="form1">
     			Username : <input id="username" type="text"><br><br>
     			Password : <input id="password" type="password"><br><br>
     			<input type="button" value="submit" onClick="Authenticate();"><br><br>
     
     			Output   : <span id="output" />
     
    		</form>
    	
    	</body>
    </html>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •