PHP OOP Login/Register System: Log in (Part 16/23)

preview_player
Показать описание

Official site

Twitter
Рекомендации по теме
Комментарии
Автор

I've been following theis series from day one & I've learned a lot from your exhaustive, vivid & easy to follow tutorials.... I'm thinking about doing a project based on what I've learned here.
GOOD JOB & Thanx a lot.

DhanaHuru
Автор

Just in case others come across the same issue I had, if when you created your database you used capital letters at the start of the words such as 'Password', when you try to retrieve data from the data() object you need to make sure you put a capital letter at the start. E.G. $this->data()->Password. If you dont it wont return an error but will just give you a blank string.

TheTechOnline
Автор

I did the following: In the salt method wrote
and my database the salt field as ntext. Using Sql Server 2005. it works!

cafedelprogramador
Автор

it's always gives me "Sorry, logging in failed" even i'am register :(

ThePapillon
Автор

Completely frustrated right now. Getting {" Notice: Trying to get property of non-object in C:\wamp....} error when trying to test code at 13:40. My code is as follows;
public function login($username = null, $password = null) {
$user = $this->find($username);

if($user) {
if($this->data()->Password === Hash::make($password, $this->data()->salt)) {
echo 'OK';
}
}
return false;
}


private function data() {
return $this->_data;
}
}
For reference, my password row in my database is a CAPITOL "P". var_dump provides a boolean false result when used instead of echo.
EDIT:::: After double checking my DB.php, I found the following;
public function first() {
return $this->results();
}
which I traced back through the videos and have changed to ;
public function first() {
return $this->results()[0];
}
Problem solved, hope this helps anyone with the same issue!

hitadinger
Автор

At 10:42, I realised that I didn't include private $_db but my data still got stored in the database, what is the purpose about having this?

pianoLee-sxdx
Автор

@Miachel Andersson: What was the solution for the 'OK!' problem?

justushoffmann
Автор

Everything has been working up to now, the test Alex runs @ 4:48 for the login.php form, if I leave the fields empty I do not get the error messages, I just get a blank page returned when submitting?

My Code is

<?php

require_once 'core/init.php';

if(Input::exists()){


$validate = new Validate();
$vaidation = $validate->check($_POST, array(
'username' => array('required' => true),
'password' => array('required' => true)
));

if($validation->passed()){
//log user in
} else {
foreach($validation->errors() as $error){
echo $error, '<br>';
}
}

}
}

?>


Can anyone advise where the issue is please?

Thanks

DavidAshby
Автор

if you are having trouble with the echo 'OK!';  at the end try making your password length in the DB longer (128 Characters)
worked for me.

Also try this code out:

public function login($username = null, $password = null) {
$user = $this->_db->get('users', array('username', '=', $username));
$user = $user->first();

($user) {
($user->password === Hash::make($password, $user->salt)) {
'OK';


TheKamerlamp
Автор

I do not get the 'OK!' message. I checked my code 20 times, a friend also checked but did not find somting wrong.

JMBA
Автор

Whats a good alternative to md5 in 2020 as now deprecated?

RSTao
Автор

HEEEE...LP ALEX

Very confused over why your code to check password OK! does not work with me.

Can print_r($this_>_data); and get correct return as per database.

I did notice from database - salt info that there are many ? in code. I looked at yours and you have none. Why is this and is this the problem preventing comparison of passwords. Any thoughts... Thanks. AND for a great series.

kevcentos
Автор

I have a question. Where does he uses prepare statements and bindValue in the login.

nickname
Автор

Hello and thank you for anyone who answers me. I copied everything exactly and follow what he is saying but the input boxes on the login and register pages look squished together and not nicely spaced and even like in this video. Is there anything i can change to make them look nicer or more like in the video?

taydll
Автор

I have a name that i registered to database like as "LYNA", but i can login with "lyna". So i can login with lowercase letters when i registered with uppercase.

nezu
Автор

the value="<?php ?>" thing keeps blocking the rest of the code from running. Is there any other way to do this? Also I struggle to understand why your approach of a db query is easier than just do the query in sql and copy-paste into the code? What will happen if you need to use joins?

dgloria
Автор

what happens when we register with the same username? does it say it is already taken? it did not in my case.

subodhpoudel
Автор

this looks much better if you put the required into the input like this -> <input type="password" id="password" class="fadeIn third" name="password" placeholder="Passwort" required>

svenlietz
Автор

Hey Alex! I have a question. If my register and login forms are in the same page, what should I do for validation? Should I put different token name for hidden inputs and then check both of them after if statements. Like this:

if(Input::exists()) {
{
// Some code here
} else {
// Some code here
}
}

ahmetozdemir
Автор

Great video in many ways:security, OO, abstraction, usability, testability. DB class is awesome. So is Config file. One question: How is it possible to declare require_once 'core/init.php' from login.php. Relative directory tells me that it should be require_once '../core/init.php'

spicytuna