-
slider16 posted...
UPDATE: RESOLVED:
I set my $_POST variable to ['hashed_password'] and did this in my register function:
function register()
{
if($_POST)
{
$user = User::create($_POST, TRUE);
$user->password = $_POST['hashed_password'];
$user->save();
redirect('login');
}
}
All good now. Password is getting hashed and saved to Users table.
Thanks again Shawn. Keep up the good work. We
out here in "Noob Land" sure appreciate it. : )
-
slider16 posted...
Shawn,
First, THANK YOU for all the great videos on PHP-ActiveRecord and Code Igniter. I've spent many hours going over your videos and learning a lot. Frankly, I consider you my CI / PHP-ActiveRecord teacher.
Now I'm trying to implement my own use of your User model "hashing" the password using a "salt." I have setup my User model exactly like you've done in this video, including the set_password setter implementation. In all the videos, I find nothing that covers registering a NEW user, or User::create(), as it were.
I am creating a register() function in my "auth" controller that is to create a new user posted from my auth\register.php view form. One of the input fields in that form is a password field named "hashed_password." My problem is that I can't get it to STORE the hashed_password into the data table. It stores the plain text version.
Here is my register() function in the auth controller:
function register()
{
if($_POST)
{
$user = User::create($_POST, TRUE);
$user->password = $_POST['hashed_password'];
}
I can step through the debugger and see that the plain text is getting hashed, I just don't see why the User object is not getting updated before saving to the table.
Thanks again.
Slider16
-
slider16 posted...
Shawn,
As in your example, the name of the password field in my table is hashed_password.
Therefore, if I set the input field in my register form to "password", and I try to use the $_POST variable $_POST['password'] in my function, i get "Undefined Index error" -- because "password" is not a field in the table.
If I do this:
$user = User::create($_POST, TRUE);
$user->password = $_POST['password'];
$user->save();
and remove "hashed_password" from the $attr_accessible array, nothing is stored in the table.
Thanks again.
-
slider16 posted...
Okay Another Update:
I have figured out how to use ['password'] instead of ['hashed_password'] for my $_POST variable. I'm creating the User model then validating the Model entirely. And if its valid I call the password "setter" in the model like so:
function register()
{
if($_POST)
{
$user = User::create($_POST, TRUE);
if ($user->is_invalid())
{
print_r($user->errors->full_messages());
}
else
{
$user->password = $_POST['password'];
$user->save();
redirect('login');
}
}
}
I'm still not sure how to use the php-active record validations on the "hashed_password" data however.
Slider
-
ian posted...
lol yep they are outdated. Looking at the comments on the codeigniter from scratch series tells me they started back in 2009 and i think the last one in the series was using 1.7.2 version. Hey Codeigniter only has two vids and they are showing how to use scaffolding. I remember seeing that video many many moons ago. Cool thing is I was able to make all the old nettuts ones work with a few minor changes.
-
groovy fellow posted...
I'm going through this as a bit of a newbie, and on the whole it's really helpful. (though occasionally a bit above my head).
But the part (around 4minutes) where you use get_instance on the CI object has lost me. And it's also throwing an error for me on the $CI->session->set_userdata('user id', $user_id); line:
Message: Undefined property: Welcome::$session
and
Fatal error: Call to a member function set_userdata() on a non-object in C:\wamp\www\ci_sparks\application\models\User.php on line 45
any ideas?
PS/ I was watching the vids on youtube and the _ci_autoloader thing had me totally stuck for a long time - might be worth putting a note about it in the youtube description or something.
-
daslicht posted...
When I craete the View as the following it is working :
Username:
Password:
Do I have to enable the short version ( = )somewhere?
-
daslicht posted...
I get no Form displayed. I have set the following in the application/config:
$autoload['helper'] = array('form');
and exactly the same code as you in my view/auth/login.php
Any idea what could got wrong ?
-
Thomas Phan posted...
Great tutorials Shawn!
I heard that CodeIgniter will integrate with Sparks in version 2.1, isn't it true? If it's so, it's very good. Thanks a lot for your tutorials, they are very clear, concise, and helpful.
I'll wait for your next screencasts.
-
Shawn McCool posted...
Your post variable should be 'password' and not hashed_password. That's created by the model. If you were to want to set it manually with $user->password = $_POST['hashed_password'] then you'd need to call $user->save(); afterwards to update the DB.
-
Shawn McCool posted...
You can enable short tags in php.ini, enable short_tag rewrites in application/config/config.php, or use long tags. I suggest either the first or last option.
-
Shawn McCool posted...
Make sure that the 'session' library is listed to autoload in config/autoload.php. (It's looking like it's not).
You're right about YouTube. I generally just use it to pull traffic to the site. But, I should make a mention.
-
Shawn McCool posted...
It sure will! 2.1 is getting quite a few nice improvements. Thanks for the kind words about the tutorials. New screencast will be coming this week.
-
Shawn McCool posted...
I do understand the change. However, there are design pattern issues with the change that was made. Minor revisions are not supposed to break pre-existing code. The update should have been held back until a later revision. I'm assuming that the change will persist, once I get confirmation that they're not going to roll it back then I'm going to update the documentation on the page and I am doing to discuss it briefly in the next screencast.
-
Quim posted...
Sorry, just solved that by removing the $ from nomedeutilizador.
I'm just trying to learn.
-
Quim posted...
Hi!
First, I want to thank you for this great tut series.
Now, I want to ask your help for an error I'm getting when running the login part. The error is:
_____________________________
A PHP Error was encountered
Severity: Notice
Message: Undefined index: $nomedeutilizador
Filename: controllers/autorizacao.php
Line Number: 10
_____________________________
Note: I changed '$username' with '$nomedeutilizador' and 'auth' with 'autorizacao'.
-
Me posted...
Man, your tutorials rock!! I've never seen any screencast as clear as yours.
I love the idea to start from scratch and to build, piece by piece, a full website.
Keep it up!!
Tim from France
-
Brian posted...
Shawn, is there a simple way to provide a "remember me" functionality to the login form?
Thanks for your answer and for the great work!
-
Anaxamaxan posted...
Great tutorial series. I just started using PHP-ActiveRecord on a project, so I'm very glad to find your tutorial.
About the _ci_autoloader() I'd say the change makes sense, since it is a public method. Just a small change in MY_Loader takes care of it: rename _ci_autoloader() without the leading underscore, and add a new _ci_autoloader() method to call it. I'm sure you know this, but I wanted to respond because of the big notice below the video player.
-
5150studiosaus posted...
Nice series mate, it's good to see more relevant CI screencasts on the net, NetTuts is great but slightly out dated at the moment. I'll be watching the next two parts next. Keep up the good work, cheers Mick