This is for a login page. I know using an array is bad practice, however this is for an assignment that asks us to use an associative array. I am running my code, however I keep getting the "invalid username and password " message when I try the credentials.This is my code for the php file:
<?php $credentials = array( 'admin1' => '@Admin1' 'admin2' => '@Admin2' 'admin3' => '@Admin3' 'admin4' => '@Admin1' ); $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; if ($credentials[$username]===$password){ echo 1; } else{ echo 0; } }
Here is my javascript
$(document).ready(function(){ $("#btn-submit").click(function(){ var username = $("#username").val().trim(); var password = $("#password").val().trim(); if( username != "" && password != "" ){ $.ajax({ url:'login.php', type:'post', data:{username:username,password:password}, success:function(response){ var msg = ""; if(response == 1){ window.location = "product.html"; }else{ msg = "Invalid username and password!"; } $("#message").html(msg); } }); } }); });
https://stackoverflow.com/questions/66978229/how-can-i-make-this-php-file-check-the-passwords-and-usernames-in-the-array April 07, 2021 at 08:47AM
没有评论:
发表评论