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

PHP 

Part1: Introduction + functions | 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

Enjoy :D

-=Introduction=-

Spoiler (Click to View)

-=Starting=-

Spoiler (Click to View)

mysql_pdo.class.php

Spoiler (Click to View)

-=functions.class.php=-

Spoiler (Click to View)

Spoiler (Click to View)

Spoiler (Click to View)

Spoiler (Click to View)

This is the end of part one of the whole tutorial.
Check out:
Part 2: Registration handling
Part 3: Login handling


Maybe coming soon [always check the last tutorial to keep this up2date!]:
Part 4: Remember me | Page Requires Login
Part 5: Delete an Account

Your sincerely,
hellomen/speed/Mike M.
Nice tutorial , keep up the good work.
I like PDO Alot because the prepared function prevents mysql injections.

Regards
[Image: eVnoInG.png]
(Aug 17, 2014 08:18 AM)t0xic-hg Wrote:  Nice tutorial , keep up the good work.
I like PDO Alot because the prepared function prevents mysql injections.

Regards

well as an user could also use MySQLi but which is limited to MySQL only
I rather use PDO to let the chances run of different databases.

yet PDO->MySQL runs on the same driver as the MySQLi driver
Horrible.
Quote:Custom build PDO class which uses PDO prepared statements to make life a bit easier XD


You're not sanitizing any input let alone you're not utilizing prepared statements.
A lot of this code is messy and over complicated and frankly makes no sense.

You should fix this, a lot.
(Aug 17, 2014 08:41 AM)Knar. Wrote:  Horrible.

You're not sanitizing any input let alone you're not utilizing prepared statements.
A lot of this code is messy and over complicated and frankly makes no sense.

You should fix this, a lot.

sorry but I just created this.
in my opinion it's not messy or comlicated at all,
yet some people always need to find "excuses" about something.
thanks for your opinion I will not use it anyways as a tip.
some people always need to find excuses about something just because others don't do it like theirs.

just a tip for you: Every coder has it's own logic

if you can't stand some namings it's not looking messy or complicated....

-I can't judge how you work because you haven't got any tutorial - source released, maybe that has a reason?-
After reading the tutorial and skimming the code, I don't think you put a lot of thought into this.
This code is acceptable for a starting PHP programmer, but not as a tutorial which should generally speaking teach newcomers how to do things the right way.

1. If the entire file is comprised of PHP, the closing tag (?>) is not required.
In fact, it's recommended in the PSR standards that you omit the closing tag.

2. You mention that the mysql_pdo.class.php uses PDO prepared statements.
This is incorrect, you're running a raw MySQL query.

3. It seems you use a class just for the sake of using a class.
You should stick to using classes with dependency injection, or functions with global variables. Not both.

4. Using stdClass in check_username and check_password is completely pointless.
These could be replaced with descriptive variables, for example $minLength.

5. You're fetching all columns from the users table in the username_exists function when a simple COUNT would suffice.
You're also storing all of the retrieved columns and then doing nothing with them.

6. In the receive_password and receive_salt functions you fetch all the columns from the users table, create an object, store the data and then return one of the fields.

7. You're limiting password length and characters and justify it with "preventing the database from crashing."
You're hashing the password, there are zero characters from the password input going to the database.
Limiting these is a big no-no and generally your users will think you're storing passwords in plaintext.

8. Since you're running raw MySQL queries instead of using prepared statements, all of the input going into your queries is unsanitised.
Granted, if you check the username using the check_username function it won't be injectable.
In any case, all user input should be handled with prepared statements.

9. You're comparing passwords without strict comparison.
In this case you should be safe since you're not using purely hexadecimal hashes.
Still, the best practice of using === instead of == to compare two hashes should be followed.

I'm sorry, it's nice that someone posts this type of a tutorial in this section, but...
This feels like a code review instead of criticising a tutorial of all things.
Please use coding standards and best practices in the next parts or don't do them at all.
Hashable.io - crowd-sourced hash cracking

"Ooh and our gods and heroes,
are only ones and zeroes.
Join hands and sing along.
Everything we know is wrong."
(Aug 17, 2014 09:30 AM)AntiPaste Wrote:  After reading the tutorial and skimming the code, I don't think you put a lot of thought into this.
This code is acceptable for a starting PHP programmer, but not as a tutorial which should generally speaking teach newcomers how to do things the right way.

1. If the entire file is comprised of PHP, the closing tag (?>) is not required.
In fact, it's recommended in the PSR standards that you omit the closing tag.

2. You mention that the mysql_pdo.class.php uses PDO prepared statements.
This is incorrect, you're running a raw MySQL query.

3. It seems you use a class just for the sake of using a class.
You should stick to using classes with dependency injection, or functions with global variables. Not both.

4. Using stdClass in check_username and check_password is completely pointless.
These could be replaced with descriptive variables, for example $minLength.

5. You're fetching all columns from the users table in the username_exists function when a simple COUNT would suffice.
You're also storing all of the retrieved columns and then doing nothing with them.

6. In the receive_password and receive_salt functions you fetch all the columns from the users table, create an object, store the data and then return one of the fields.

7. You're limiting password length and characters and justify it with "preventing the database from crashing."
You're hashing the password, there are zero characters from the password input going to the database.
Limiting these is a big no-no and generally your users will think you're storing passwords in plaintext.

8. Since you're running raw MySQL queries instead of using prepared statements, all of the input going into your queries is unsanitised.
Granted, if you check the username using the check_username function it won't be injectable.
In any case, all user input should be handled with prepared statements.

9. You're comparing passwords without strict comparison.
In this case you should be safe since you're not using purely hexadecimal hashes.
Still, the best practice of using === instead of == to compare two hashes should be followed.

I'm sorry, it's nice that someone posts this type of a tutorial in this section, but...
This feels like a code review instead of criticising a tutorial of all things.
Please use coding standards and best practices in the next parts or don't do them at all.

1) Thanks for that I didn't know that I just always do it because I learned it that way xD

2) sorry for the mistype of prepared statement I was look to another login script of my forum software.
my excuses is now said into the introduction that it is NOT using PDO's prepared statements

3) the usage of the class was just to stick everything together as I was planning to use different classes before for register and login...
but I changed my mind in the last minutes
-----
remains the same

4) the reason I use stdClass is because it looks better
since the min-username length & max-username length and username length are all going about length
so I created an object of $length to give it properties (min - max - username) so it refers all to the length
----
remains the same

5) I agree with the counting I should have used it but hehe we all want to copy paste something once in a while after you created it :)
will add it as a note :D

the storing every content doesn't effect the performance, and was only for the testing if each is read/shown and once again it goes into the c+p part xD
----
has been edited in the login/register script
not in the threads [note added]

6) thanks for the tip I will look into that, this is prety much the only way I looked at it but also the c+p part counts here.
----
will be looked into it

7) I always use it like this because I think it's simpler and just inline
if it goes into multiple lines in a query I most likely use it spaced out...
----
will be looked into it

8) indeed both must be same so the stricter way (===) should be used
----
has been edited in the login/register script
not in the threads [note added]

Thanks for the tips,
I hope yours is answered aswell on why it is like this.
If you have more feel free to say it :D
I have a problem with amateurs teaching amateurs.
This is overly complicated for a login/register script. All that's really needed is a few queries. No functions at all.
(Aug 17, 2014 12:26 PM)Cathal Wrote:  I have a problem with amateurs teaching amateurs.

I have a problem with people like you that don't add anything sense in posts behave bs/low quality...

(Aug 17, 2014 12:39 PM)Programming Wrote:  This is overly complicated for a login/register script. All that's really needed is a few queries. No functions at all.

I just used functions for additional things I am planning to do, next time ask before complaining.

-edit: keep complaining please, never posted a thread in the php section about your own releases/tutorials/sources but ye keep complaining.-

@all:

all that complaining about too complicated blablabla...
as long as it's understandable don't complain about it's being to complicated because if you think it is, then you should check back your own php scripts and see if that's "too complicated" aswell

I am just going to help other and never gona release a single tutorial on these shitty community jeez.
I left before because of these kiddies and probably will go again.

the only one that posted some quality reply is @AntiPaste - creds to you for your awesomeness and being a human.
(Aug 17, 2014 01:08 PM)hellomen Wrote:  I have a problem with people like you that don't add anything sense in posts behave bs/low quality...

Why the hell are you making a tutorial on something you're obviously only new to yourself? I mean, kudos for taking the time, but realistically all you're doing is teaching others to learn the wrong things, the wrong ways. I had a geography teacher once who couldn't teach geography, because he didn't know the course nor the subject. I damn near failed my Geography. This is no different. I feel sorry for anyone unfortunate enough to stumble across this thread while trying to understand OOP.

Does that make fucking sense?

Do you understand why I'm pissed off? (There are 11.5 million pages of this)

EDIT: Oh my.. Then you have the audacity to call us kiddies? Do us all a favor and follow the link in my signature, if that's not too complicated for you.
(Aug 17, 2014 01:15 PM)Cathal Wrote:  Why the hell are you making a tutorial on something you're obviously only new to yourself? I mean, kudos for taking the time, but realistically all you're doing is teaching others to learn the wrong things, the wrong ways. I had a geography teacher once who couldn't teach geography, because he didn't know the course nor the subject. I damn near failed my Geography. This is no different. I feel sorry for anyone unfortunate enough to stumble across this thread while trying to understand OOP.

Does that make fucking sense?

Do you understand why I'm pissed off? (There are 11.5 million pages of this)

EDIT: Oh my.. Then you have the audacity to call us kiddies? k

what makes the FUCKING SENSE to post low quality shit as:
I have problem with amateurs teaching amateurs

MATE WELCOME TO THE INTERNET. WE ALL ARE AMATEURS EVEN YOU.!.
seriously that post make no fucking sense at all, you want it like that you get it like that but don't come whining back and ye you're a kiddie

good luck fucklord -.- jeez fuck off out of this thread unless you have something USEFULL to say like @AntiPaste did

I am prety sure EVERYTHING is already made before that has been put on here

I seen people here having problems with logins/register
I made a simple WORKING TESTER TUTORIAL how to create one

and you're going to bitch here because it is already on the internet?

if you are like that go away and disable your internet because almost everything is already on the internet, go lock yourself up, it's already on the internet how to do that, which gets you mad aswell.
(Aug 17, 2014 01:43 PM)hellomen Wrote:  what does this put me for kind of information behave your silly opinion?

Being serious; what do you even mean? I honestly can't grasp what you're trying to say in that sentence.
(Aug 17, 2014 01:44 PM)Builder_Geeza Wrote:  Being serious; what do you even mean? I honestly can't grasp what you're trying to say in that sentence.

easily let's take it's sentence apart:
1) It was your silly opinion
2) It is nothing usefull for me what you just write there.
(Aug 17, 2014 01:46 PM)hellomen Wrote:  easily let's take it's sentence apart:
1) It was your silly opinion
2) It is nothing usefull for me what you just write there.

It wasn't an opinion; it was a statement.

And honestly I'm just not going to reply if you can't be bothered to either spell correctly or form your sentences so they actually make sense.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by DavidIAJan 24, 2019 12:44 PM 9 355 Jan 24, 2019 12:44 PM
Last Post: DavidIA
[PHP] by alemalakraMay 3, 2017 06:22 AM 57 2,615 May 3, 2017 06:22 AM
Last Post: Squito
[PHP] by StreamahNov 20, 2016 11:34 AM 6 363 Nov 20, 2016 11:34 AM
Last Post: Matt AH