Hey, did everyone they share in this video?
We are going to work on the methods previously we worked on to the pre which are the hooks.
So I have added the hooks here as in the comments section as well.
So user dot pre is actually hooks.
Similarly, we have user dot post as well.
Right now we don't have any strict necessity of having this post and everything, so we don't need to
work on that.
Now further down the road, a user dot methods is what we are going to use to define some of the methods.
So let's go ahead and do that.
We're going to go ahead and say the same user schema dot and yes, at this exact same time, if you
were yelling at me, then you are absolutely paying a lot of attention.
If not, then pay more attention, my friends, because I was writing this method right after exporting
and this is not how it works.
And I've seen people making this mistake, so please don't do this.
Let's go ahead and move this up here.
So this is where exactly it needs to go.
So again, a little bit exercise.
So what you need to do is just like we have these pre and post, we have these methods, make sure there
is an SX here and you can write as many methods as you like.
What we are writing here is to validate the passwords because obviously we need to compare the password
from whatever the user has entered in their login field.
And since we can actually make this a method because we have the existing password, we have the B script
as well.
So why not to just check the password as in the method?
So somebody can just say user dot email, he can also say user validate password, something like that.
So let's add a comment and we are going to say validate the password with passed on user password.
So obviously we need something with what the user is now passing in and we need to take something from
the database itself.
So really simple.
So how we are going to go ahead and do that?
We are going to call this one as is password validated or we're going to call this one as validate password.
Again, feel free to name it better in case you are going with that.
This is going to be a sync because remember database is always on some another continent and it might
take some time.
We're going to have a simple function just like this and there we go.
Now this function will take only one parameter which is passed password.
Let's call this one as user password or user send password.
I'm running out of the name.
Okay.
You can call this whatever you like.
So this is the user sent password.
So how we are going to kind of check this one again, we have already checked that that script actually
does this job for us.
So we're going to go ahead and say, Hey Bee script, please go ahead and compare the password.
So the script is going to compare the password with let's go ahead and say that this is the password
needs to become paired with user send a password and we can access the property by saying this dot password.
There we go.
Now, not only this, this is going to take some time.
So we're going to say a wait and also we're going to go ahead and return this one.
So what this will do again, we have seen that script compare returns you just to true and false as
a value.
So we don't have to worry on that part.
You need to just pass on again.
These fields doesn't really matter which one you pass on.
First, there's not password or user sent password.
This really means same.
And all we got here is now a simple, true and false method.
Whether the password are same and anybody can use whatever they are calling this user, for example.
So just like they say, they start email to access my email, they can now say validate password which
will give a true or false result.
I usually like to pass on something like this is is validate password so something like this so that
I know really that this is a true and false event.
So I'm going to keep it like this.
So let's keep it as lowercase is a validate password.
Again, this is a horrible name.
Let's go ahead and think for something different up here is validated password.
So this seems okay for as of now is validated password again not really a big fan of the naming up here.
But again, I really just want to give you the basic idea of that.
Let's go ahead and catch up in the next video.