Mr Scratch
Expert Member
- Joined
- May 15, 2013
- Messages
- 4,838
Your variable naming convention.
simple form based authentication is fine. no need to overkill with token based, or oauth.
those can be added as an additional layer anytime anyway.
please stop abbreviating things. what is the point of omitting the `e` in `usr_id` and `usr_name`?
also, pick a style for variable names, and stick to it. `$succcessmsg` vs `$password_error`. that is not consistent.
http://www.php-fig.org/psr/psr-1/
http://www.php-fig.org/psr/psr-2/
When ever I use sessions or cookies I use usr whenever I interact with the DB I use user it is for me I am the only working on it.
I am quite consistent in my variables
$name_error
$email_error
$password_error
$cpassword_error
then
$successmsg
or
$errormsg
$errorMessages['name'] = //
$errorMessages['email'] = //
$errorMessages['password'] = //
$errorMessages['confirmPassword'] = //
foreach ($errorMessages as $errorMessage) {
echo '<span>'.$errorMessage.'</span>';
}
what about from a file? double underscores, skipping each even index letter of the alphabet.
you do know that a session, or a cookie, is a database?
so not consistent at all
in all seriousness though, for your validation I would rather user an `errors` array.
PHP:$errorMessages['name'] = // $errorMessages['email'] = // $errorMessages['password'] = // $errorMessages['confirmPassword'] = //
now your validation output could easily change in the future.
eg
PHP:foreach ($errorMessages as $errorMessage) { echo '<span>'.$errorMessage.'</span>'; }
also, IMO, there is no such thing as an $errormsg, or a $successmsg.
There is a $status, and a $message
foreach ($errorMessages as $errorMessage) {
echo '<span>'.$errorMessage.'</span>';
}
what about from a file? double underscores, skipping each even index letter of the alphabet.
you do know that a session, or a cookie, is a database?
$errors['password']['required'] = 'password is required';
$errors['password']['min'] = 'password must be 6 chars';
$errors['password']['regex '] = 'password must be 3 letters and 3 numbers';
<div class="form-group">
<label for="password>Password</label>
<input type="password" name="password" />
<?php
foreach ($errorMessages['password'] as $errorMessage) {
echo '<span class="text-danger">'.$errorMessage.'</span>';
}
?>
</div>
{
errors: [
password: {
required: "password is required",
min: "password must be 6 chars",
regex: "password must be 3 letters and 3 numbers"
}
]
}
simple form based authentication is fine. no need to overkill with token based, or oauth.
learn to walk before running and all that.
maybe quote me with the rest of my post as context??
I want to learn, I want to see and understand what the process involves I want be low level I want to write and build APIs for the language one day. I really feel if we keep telling people don't do it yourself copy and paste leverage the community then 10 years from now you won't have programmers anymore you'll just have a bunch of monkies that's my view anyway.Agreed!
Best Practice for Authentication -> Don't Roll your own.
I agree to an extent but there are some pieces where using an already created best practice is best and user authentication and management and session management are one (three) of them.I really feel if we keep telling people don't do it yourself copy and paste leverage the community then 10 years from now you won't have programmers anymore you'll just have a bunch of monkies that's my view anyway.
That's a good approach to take... building something yourself always implies an informed decision. Just do your research, there is no reason why you can't build something secure.I want to learn, I want to see and understand what the process involves I want be low level I want to write and build APIs for the language one day. I really feel if we keep telling people don't do it yourself copy and paste leverage the community then 10 years from now you won't have programmers anymore you'll just have a bunch of monkies that's my view anyway.
Not afraid. When your end goal is to have whatever Thor is planning on building (I can't reacall if he has said what it is but I don't think it's a login component) then you don't want to be spending 4 months developing and testing your login component....They are afraid, Don’t blame them. But don’t let that stop you from building your own system.
and can be more secure than system developed by people like Google and FB. The bigger the company the Bigger the target the bigger the reward for hacking it.
My2c
Instead of trying to slap an authentication system together for an existing project. Rather totally forget about the existing project and treat the authentication part as a totally new project.
Design it in such a way that it can be re-used in future projects.
The reason why people give you the “Leave it to the pros” attitude is because security should not be taken lightly. They are afraid, Don’t blame them. But don’t let that stop you from building your own system.
Being the purest that I am I don’t like depending on other people’s code. Non-standard practices aren’t necessarily a sin and can be more secure than system developed by people like Google and FB. The bigger the company the Bigger the target the bigger the reward for hacking it.