Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Part 3: Login handling | Login/Register Script

Dear reader,

Thanks for coming by on this thread to follow my tutorial!

We will have a little introduction first and and then we can start:)

Parts:
1) Introduction + Functions
2) Registration Handling
3) Login Handling

Please be aware without part 1 and part 2, you will not be anywhere at this part.

Enjoy :D

-=Introduction=-

Spoiler (Click to View)

-=login.php=-

Spoiler (Click to View)

-=checkLogin.php=-

Spoiler (Click to View)

-=doLogin.php=-

Spoiler (Click to View)

This is the end of part three of the whole tutorial.
Check out:
Part 1: Introduction + functions
Part 2: Registration handling


Maybe coming soon [always check the last tutorial for the coming soons]:
Part 4: Remember me | Page Requires Login
Part 5: Delete an Account

Your sincerely,
hellomen/speed/Mike M.
(Aug 17, 2014 01:28 PM)Cathal Wrote:  Oh dear God https://puu.sh/aWFu6/d5c16b0f44.png

Free rep to whoever can spot all the mistakes and malpractices.

Too much Nested If statements. No need to do ==true since by default it would be true.

I don't really know PHP that well so ya.
(Aug 17, 2014 01:32 PM)+Haze Wrote:  Too much Nested If statements. No need to do ==true since by default it would be true.

I don't really know PHP that well so ya.

I never really get how you can fix the nested if statements
since each will output a difference and I believe a switch is only for 1 statement at the time

as for the equals try, yes it does that by default but it just makes it more clear for people who's totally new in php

(Aug 17, 2014 01:33 PM)Cathal Wrote:  Good! Fingers crossed they see all the flame you left me.

says the one starting fights here.

seriously fuck away with low quality posts

the kid that reports my paste will probably never be able to use pastebin again for false report
{ip ban}
(Aug 17, 2014 01:35 PM)hellomen Wrote:  I never really get how you can fix the nested if statements
since each will output a difference and I believe a switch is only for 1 statement at the time

as for the equals try, yes it does that by default but it just makes it more clear for people who's totally new in php

says the one starting fights here.

seriously fuck away with low quality posts

the kid that reports my paste will probably never be able to use pastebin again for false report
{ip ban}

There's no need to be throwing a hissy fit on HF. If you don't like someone, then you should get off the internet or ignore them.

I do think that it's nice you are creating a "tutorial" for people who would like to create a login/registration system, although I would suggest you to improve your tutorial and code a bit. There seems to be a lot of code that doesn't follow any standards. You should also improve your tutorial to explain a bit more what is happening and such. A lot of your code can be improved to make more sense.

For example, why are you unsetting $warning when it hasn't been set?
PHP Code

<?php 
default:  //there is no warning
  //$warning = "none";
  
unset($warning);
  break; 

Seems like your database is extending PDO and then it creates a new PDO class? An it seems like your database class doesn't even use prepared statements as you said it did?

Directly using $username without sanitization? Nope!
PHP Code

<?php 
$query 
= $con->runQuery("SELECT * FROM `users` WHERE `username`='".$username."'"); 

Of all of the years I've been programming, this made me wat all over the place.
PHP Code

<?php 
$length 
= new stdClass();
$length->min = 4;
$length->max = 10;
$length->username = strlen($username);
if(
$length->username >= $length->min && $length->username <= $length->max){
        return 
ctype_alnum($username);
}else{
        return 
false;
} 

You could just do
PHP Code

<?php 
return (strlen($username) >= 4 && strlen($username) <= 10 && ctype_alnum($username)); 

I don't want to be a bashful asshole, I just want to help you out. If you're going to make a tutorial, I would suggest you to improve your code to make more sense a bit, and stick to standards.

You shouldn't teach people shit code.

Edit:
Just want to know, why use a maximum password length? I use password that are longer than 20 characters. And why restrict the password? If you're going to hash/encrypt it, why does it matter on the length or what the characters are? I'm sure others use long passwords with complex and special characters.
PHP Code

<?php 
public function check_password($password){
        
$length = new stdClass();
        
$length->min = 6;
        
$length->max = 20;
        
$regex = '/^[a-zA-Z0-9 \!\@\#\$\%\^\&\*]{'.$length->min.','.$length->max.'}$/';
        if(
preg_match($regex, $password)){
                return 
true;
        }else{
                return 
false;
        }
} 
(Aug 17, 2014 03:51 PM)AppleJuice Wrote:  There's no need to be throwing a hissy fit on HF. If you don't like someone, then you should get off the internet or ignore them.

I do think that it's nice you are creating a "tutorial" for people who would like to create a login/registration system, although I would suggest you to improve your tutorial and code a bit. There seems to be a lot of code that doesn't follow any standards. You should also improve your tutorial to explain a bit more what is happening and such. A lot of your code can be improved to make more sense.

For example, why are you unsetting $warning when it hasn't been set?
PHP Code

<?php 
default:  //there is no warning
  //$warning = "none";
  
unset($warning);
  break; 

Seems like your database is extending PDO and then it creates a new PDO class? An it seems like your database class doesn't even use prepared statements as you said it did?

Directly using $username without sanitization? Nope!
PHP Code

<?php 
$query 
= $con->runQuery("SELECT * FROM `users` WHERE `username`='".$username."'"); 

Of all of the years I've been programming, this made me wat all over the place.
PHP Code

<?php 
$length 
= new stdClass();
$length->min = 4;
$length->max = 10;
$length->username = strlen($username);
if(
$length->username >= $length->min && $length->username <= $length->max){
        return 
ctype_alnum($username);
}else{
        return 
false;
} 

You could just do
PHP Code

<?php 
return (strlen($username) >= 4 && strlen($username) <= 10 && ctype_alnum($username)); 

I don't want to be a bashful asshole, I just want to help you out. If you're going to make a tutorial, I would suggest you to improve your code to make more sense a bit, and stick to standards.

You shouldn't teach people shit code.

Edit:
Just want to know, why use a maximum password length? I use password that are longer than 20 characters. And why restrict the password? If you're going to hash/encrypt it, why does it matter on the length or what the characters are? I'm sure others use long passwords with complex and special characters.
PHP Code

<?php 
public function check_password($password){
        
$length = new stdClass();
        
$length->min = 6;
        
$length->max = 20;
        
$regex = '/^[a-zA-Z0-9 \!\@\#\$\%\^\&\*]{'.$length->min.','.$length->max.'}$/';
        if(
preg_match($regex, $password)){
                return 
true;
        }else{
                return 
false;
        }
} 

Code
There's no need to be throwing a hissy fit on HF. If you don't like someone, then you should get off the internet or ignore them.
if that bitch please guy keeps posting low quality shit ye I start swearing at that kid.
read his previous posts, it doesn't give tips.

Code
Seems like your database is extending PDO and then it creates a new PDO class? An it seems like your database class doesn't even use prepared statements as you said it did?

read part 1 of the tutorial there is a note in the intro you'd see were I got in the mistake.

Code
return (strlen($username) >= 4 && strlen($username) <= 10 && ctype_alnum($username));
this looks indeed shorter but not nicer for beginners
they don't like such codes because it's too long or confusing, I have been in it too while seeing stuff like this.

Code
You shouldn't teach people shit code.

that's your opinion
I heard from others it is fine in it's ways.

Code
Just want to know, why use a maximum password length? I use password that are longer than 20 characters. And why restrict the password? If you're going to hash/encrypt it, why does it matter on the length or what the characters are? I'm sure others use long passwords with complex and special characters

the 20chars maximum was only for the limitation as showing that it is possible.

as far as the limited character goes since we are using strip_tags();
it will cut out html special characters
as if we make sure we only allow !-@-#-$-%-^-&-* and a-Z 0-9 we make sure no special character has been inputted

the minimal password length should always be inserted but I do recommend to keep it limited to 255 characters as if a password isn't really longer than 255

thanks for your input.

Edit:
I am prety sure cathal reported my paste.
but I am not going into conclussions since I have no rights to do that with him even when he's a hater.

for the reporter:
it's fine that you have personal issue's, but leave my stuff alone.
I am in contact with pastebin to get you off from their servers since this is way to inappropriate.
(Aug 18, 2014 08:43 AM)Cathal Wrote:  I didn't report your paste. I'm also just gonna stop replying because you're too dumb to listen. Have you stopped to think why everyone has taken my side in this multi-thread argument? Because you're the only one who fails to understand what I'm saying.

Cathal, just leave it, he's not worth wasting your time on


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Javascript]  by HardStoNNov 16, 2020 09:19 AM 12 332 Nov 16, 2020 09:19 AM
Last Post: woodly
[PHP] by guaJun 11, 2019 02:33 PM 5 204 Jun 11, 2019 02:33 PM
Last Post: Charger
[PHP] by DavidIAJan 24, 2019 12:44 PM 9 358 Jan 24, 2019 12:44 PM
Last Post: DavidIA