Jump to content

Recommended Posts

Hey guys!

 

Thanks for the wonderful forum! I am new to php programming and I am trying to do a login form by codecourse on youtube, perhaps it will help if I put the link here so someone could try to tell me where I have gone wrong...https://www.youtube.com/watch?v=AtivJV-kx5c

 

For some reason, around the 4:40 minute mark in the tutorial, I am unable to get the username is required and password is required to be displayed on the screen when clicking on the submit button. Here is my code. I can't seem to find any errors. Thanks!

 

<?php
require_once 'core/init.php';
 
if(Input::exists()) {                                              // check to see if input exists or not....
if(Token::check(Input::get('token'))) {                        // check that the token is correct and suppy by the form
 
$validate = new Validate();
$validation = $validate->check($_POST, array(
  'username' => array('required' => true),
  'password' => array('required' => true)
));
 
if($validation->passed()) {
   $user = new User();                         // log user in.... make a new object so that we use the method
   $login = $user->login(Input::get('username'), Input::get('password'));
 
if($login) {                               // check to see if login is successful or not
echo 'Success';
} else{
echo '<p>Sorry, logging has failed!</p>';
}
 
} else {
foreach($validation->errors() as $error) {
echo $error, '<br>';
}
}
}
}
 
 
?>
 
 
 
 
 
<form action="" method="POST">
   <div class="field">
      <label for="username">Username</label>
 <input type="text" name="username" id="username" autocomplete="off">
   </div>
   
    <div class="field">
      <label for="password">Password</label>
 <input type="password" name="password" id="password" autocomplete="off">
   </div>
   
   <input type="hidden" name="token" value="<? php echo Token::generate(); ?>">
   <input type="submit" value="Log in">
</form>
 
<!--     To generate a token, use: <? php echo Token::generate(); ?> in the value="" section  -->
 
Link to comment
https://forums.phpfreaks.com/topic/301563-php-oop-login-system-not-working/
Share on other sites

So what does happen when you leave the fields empty? Are you getting an error? A blank page? Are you magically logged in?

 

Be specific. Programming is an exact science, not a guessing game.

 

Right now, all I can tell you is that a lot of your checks lack an else branch. If there are no POST parameters, or if the token is wrong, you keep quiet and don't give any feedback at all, which is obviously a problem.

Edited by Jacques1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.