We'regonnacreate a rabbithere, butyou'regonnabeapt.
I getitiswe'regettingallofourusers.
Andwhenyoucreate a realapplication, you'renotgonnawannahave a routethatexposesyouruser's passwordinformation.
Butfortestingpurposesandtoshowyouhowthisworks, we'regonnacreatethisusersroute, soshe's gonnabeatslashusers, andit's goingtocomeinherewith a requestand a response.
Andallwe'regonnadoiswejustwanttosendthatusers.
Sowe'regonnasayresponsedotJasonandwewanttosendouruserssoit's createdusersvariableorwe'regonnastoreusersin a realapplicationyouwouldmostlike.
Wewanttostorethisin a databasesomewhere, butfortestingpurposes, just a localvariablewillbejustfine.
If a potentialmaliciouspersongetsaccesstoourdatabaseandtheycrackedonepassword, they'reabletocrackeveryotherpasswordthatlooksexactlythesameandhasthesamehash.
Andifwerunthisagainwiththeexactsamepasswordandthequicksendrequest, you'llseeweget a differentsalt, whichgeneratesus a brandnew, differentpasswordattheendhereandnow.
Totestthatevenfurther, wecanget a listofallofourusers, andyoucanseewehavethathashedpasswordbeingstored.
Also, becrypthas a nicewayofdoingbothgeneratingassaultandhashinthepasswordinonesinglestep, andwecouldjustremovethissaltsectionandinhereinsteadofpassingassault.
ComedownhereappdotPostandwewon't opposetousersslashusersslashBlufganandthisisgoingtotakeinrequestand a responsewereagaingoingtomakethisanasynchronousfunctionbecausewe'regonnausebecrypt, whichisanasynchronouslibrarytoabletocompareourpasswords.
Nowthefirstthingweneedtodoisgetourusersowecanjustcreate a variablehere, whichisuser, andthat's goingtobeequaltotakingourusersvariable.
Andwe'retryingtofind a particularuserbasedonthenamewepassedin.
Soiftheuserdotnameisequaltorequestthatbodythatname, thenweknowthatwefound a userfromourinitiallist.
Thisisjustmatchingonthenameandwecancomeinhere, put a singleifstatementwhichwanttomakesurethatuseractuallyexist.
Andifforsomereasonthisdidn't workthesepasswordsornotthisnameandwecouldjustsendsomethingdownherethatsaysnotallowednowthatwehavethatallsavedwascreate a usersowecanjustsendthispostrequestAndwecansay, herewehaveouruserKylecreated.
Andnowlet's trytologtheminwith a differentpassword.