Jump to content

student trying to make password checker

shadowss

 

Hello im a student which is trying to make a program which checks if my password is 8 chars long otherwise people should not be allowed to login but cant really get it to work im only allowed to use javascript, php and HTML

could any of you look at my code and maybe point me toward something or say what im missing here to be able to check if the password is 8 chars long and only login if it is?

 

<?php 
	// lavet af ida, jonas og troels
	session_start(); // her starter vi en session
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>

	<?php
require_once '/var/www/wits.ruc.dk/db.php';
if(isset($_POST['uid'])){   // vi siger hvis $_post['uid'] er tilgængeligt så kør koden under
	add_user($_POST['uid'],$_POST["uid"],"tea","12345678"); // her tilføjer vi bruger til at gøre så vi kan logge ind med den

	$bruger = $_POST['uid'];    // her definere vi vores bruger 
	$logget_ind = login($_POST['uid'], $_POST['password']); // her logger vi ind ved hjælp af uid og password some vi skriver i form

	if (strlen($_POST['password']) >= 8) {
		$logget_ind = login($_POST['uid'], $_POST['password']); // Forsøger at logge ind med angivet brugernavn og adgangskode.
	}

	if ($logget_ind === true){  // her siger vi hvis logget_ind er true så skal den kører kode eller så skal den sende os tilbage til login 

		$_SESSION['brugernavn'] = $bruger;
		header("Location: opret_opslag.php");   // her sender den os til vores andet sted på hjemmeside 
		setcookie("brugernavn", 8, time() + (2*60000)); // dette er vores cookie som siger navn for den er brugernavn, value er 8, og tid er time + 2*60000 som er tiden før den løber ud 
	exit;
	}
	else {

		header("Location: login-side.php"); 
	exit;
	}

}
else {  // her er vores form 
	echo <<<END
	<form method="POST">
		<label>Navn</label>
		<input type="text" name="uid"> <br>
		<label>Password</label>
		<input type="password" name="password">
		<button onclick="checkPasswordLength()">Tjek kodeord</button>
		<input type="submit" value="Log ind">
	</form>

	<script>
			function checkPasswordLength() {
				var password = document.querySelector('input[name="password"]').value;
				// Henter kodeordet, som brugeren har indtastet.
				if (password.length >= 8) {
					// Tjekker om kodeordet er mindst 8 karakterer langt.
					document.getElementById("submitButton").style.display = "block";
					// Viser submit-knappen, hvis kravet er opfyldt.
				} else {
					alert("Kodeordet skal være mindst 8 karakterer langt.");
					// Viser en fejlmeddelelse, hvis kravet ikke er opfyldt.
				}
			}
		</script>

	END;
}



?>


</body>
</html>

 

Link to comment
Share on other sites

Link to post
Share on other sites

Please post your code into a code tag, rather than posting a screenshot of your code. That makes it a lot easier for people to read and more importantly to copy & paste to test and play around with your code.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Eigenvektor said:

Please post your code into a code tag, rather than posting a screenshot of your code. That makes it a lot easier for people to read and more importantly to copy & paste to test and play around with your code.

ty for saying that ill do that rn 

 

Link to comment
Share on other sites

Link to post
Share on other sites

This login() call attempts to log the user in regardless of password length.

$bruger = $_POST['uid'];    // her definere vi vores bruger 
$logget_ind = login($_POST['uid'], $_POST['password']);

Could you remove the second line?

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Ominous said:

This login() call attempts to log the user in regardless of password length.

$bruger = $_POST['uid'];    // her definere vi vores bruger 
$logget_ind = login($_POST['uid'], $_POST['password']);

Could you remove the second line?

thats the function to be able to login we found out how to do it we just added this 

    $logget_ind = login($_POST['uid'], $_POST['password']);
} else {
    $logget_ind = false; // Indstil logget_ind til false, hvis kravet ikke er opfyldt

and changed the submit button to this 

<input type="submit" id="submitButton" value="Log ind" style="display: none;">

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×