laravel Óû§ÃÜÂëÔõôÄð³É¹þÏ£Öµ
laravelÊÇÒ»¿î¿ªÔ´µÄphp webÓ¦ÓóÌÐò¿ò¼Ü£¬ËüÌṩÁËÒ»ÖÖÓÅÑŶøÇáÓ¯µÄ·½·¨À´¹¹½¨webÓ¦ÓóÌÐò¡£ÔÚlaravel¿ò¼ÜÖУ¬Óû§ÃÜÂëĬÈϻᱻ¹þÏ££¨hash£©¼ÓÃÜ´æ´¢¡£±¾ÎĽ«»áÏÈÈÝlaravel¿ò¼ÜÖÐÓû§ÃÜÂëÔõÑùÄð³É¹þÏ£Öµ¡£
Ò»¡¢Ê²Ã´ÊǹþÏ£Öµ£¿
¹þÏ£Öµ£¨Hash Value£©£¬Ò²±»³ÆΪɢÁÐÖµ£¨Hash Code£©£¬ÊÇÒ»ÖÖ¿ÉÒÔʹí§Òâ¾ÞϸÊý¾ÝÓ³Éäµ½Àο¿¾ÞϸÊý¾ÝµÄÖµ¡£¹þϣֵͨ³£ÒÔ×Ö·û´®µÄÐÎʽÌåÏÖ£¬Ëü¿ÉÒÔÓÃÀ´¾ÙÐÐÊý¾ÝµÄ²éÕÒ¡¢½ÏÁ¿¼°ÍêÕûÐÔÑéÖ¤µÈ¡£
¹þÏ£Ëã·¨ÊÇÒ»ÖÖ¶ÔÐÅÏ¢¾ÙÐмÓÃܵÄÒªÁ죬Ëü¿ÉÒÔ½«í§Òⳤ¶ÈµÄÊý¾Ýת»»ÎªÀο¿³¤¶ÈµÄ¹þÏ£Öµ¡£ÔÚ¹þÏ£Ëã·¨ÖУ¬²î±ðµÄÊý¾Ý¿ÉÄܻᱬ·¢ÏàͬµÄ¹þÏ£Öµ£¬Õâ±»³ÆΪ¹þÏ£³åÍ»¡£
¶þ¡¢ÎªÊ²Ã´Òª½«Óû§ÃÜÂëÄð³É¹þÏ£Öµ£¿
ÔÚWebÓ¦ÓóÌÐòÖУ¬Óû§ÃÜÂëÊǺÜÊÇÃô¸ÐµÄÊý¾Ý¡£ÈôÊÇÓû§ÃÜÂëÃ÷ÎÄ´æ´¢ÔÚÊý¾Ý¿âÖУ¬Ò»µ©Êý¾Ý¿â×ß©£¬ÕâЩÃÜÂ뽫»á±»Ì»Â¶£¬µ¼ÖÂÓû§µÄСÎÒ˽ÈËÐÅÏ¢±»²»Á¼·Ö×Ó¶ñÒâʹÓá£
Òò´Ë£¬½«Óû§ÃÜÂë¹þÏ£»¯ÊÇÒ»ÖÖ±£»¤Óû§Òþ˽µÄÓÐÓ÷½·¨¡£Í¨¹ý¹þÏ£Ëã·¨£¬½«Óû§ÃÜÂëת»¯Îª²»¿ÉÄæµÄ¹þÏ£Öµ´æ´¢ÔÚÊý¾Ý¿âÖУ¬×ÝÈ»Êý¾Ý¿â×ß©£¬ºÚ¿ÍÒ²ÎÞ·¨Ö±½Ó»ñÈ¡Óû§ÃÜÂë¡£
Èý¡¢Laravel¿ò¼ÜÖеĹþÏ£¼ÓÃÜ
ÔÚLaravel¿ò¼ÜÖУ¬¹þÏ£¼ÓÃܱ»ÆÕ±éÓ¦ÓÃÓÚ±£»¤Óû§ÃÜÂë¡£µ±Óû§×¢²áʱ£¬Laravel»á½«Óû§ÃÜÂëͨ¹ý¹þÏ£¼ÓÃÜË㷨ת»¯³É¹þÏ£Öµ£¬²¢½«Æä´æ´¢ÔÚÊý¾Ý¿âÖС£ÔÚÓû§µÇ¼ʱ£¬Laravel»á½«Óû§ÊäÈëµÄÃÜÂë¾ÙÐйþÏ£¼ÓÃܺóÓëÊý¾Ý¿âÖеĹþÏ£Öµ¾ÙÐбȶԣ¬ÈôÊÇÆ¥ÅäÀֳɣ¬ÔòÒÔΪÓû§ÊäÈëµÄÃÜÂëÊÇ׼ȷµÄ¡£
Laravel¿ò¼ÜÖеĹþÏ£¼ÓÃÜË㷨ĬÈÏʹÓÃBCrypt¡£BCryptÊÇÒ»ÖÖ»ùÓÚÃÜÂëѧHashº¯ÊýµÄ¼ÓÃÜËã·¨£¬Ëü¿ÉÒÔ½«í§Òⳤ¶ÈµÄÊý¾Ýת»»ÎªÀο¿³¤¶ÈµÄ¹þÏ£Öµ£¬²¢ÇÒ¹þÏ£Öµ¾ßÓÐΨһÐÔ¡¢²»¿ÉÄæÐÔºÍËæ»úÐÔµÈÌص㣬°ü¹ÜÁËÃÜÂëµÄÇå¾²ÐÔ¡£
ËÄ¡¢Laravel¿ò¼ÜÖÐÔõÑù¾ÙÐйþÏ£¼ÓÃÜ
Laravel¿ò¼ÜÖÐÄÚÖÃÁËHashÃÅÃ棨Facade£©£¬¿ÉÒÔºÜÀû±ãµØ¾ÙÐйþÏ£¼ÓÃܲÙ×÷¡£HashÃÅÃæÌṩÁËһЩҪÁ죬¿ÉÒÔͨ¹ý²î±ðµÄ²ÎÊýÀ´Ö¸¶¨¹þÏ£¼ÓÃܵķ½·¨ºÍÇ¿¶ÈÆ·¼¶¡£
ÀýÈ磬½«Óû§ÃÜÂë¾ÙÐйþÏ£¼ÓÃܵķ½·¨¿ÉÒÔͨ¹ýÈçÏ´úÂëʵÏÖ£º
use IlluminateSupportFacadesHash; $password = '123456'; // ʹÓÃĬÈÏÉèÖþÙÐÐÃÜÂë¹þÏ£¼ÓÃÜ $hashed_password = Hash::make($password);
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬Ê¹ÓÃĬÈÏÉèÖÃʵÏÖ¹þÏ£¼ÓÃÜ£¬Ä¬ÈϵĹþÏ£Ë㷨ΪBCrypt£¬Ê¹ÓÃBlowfishËã·¨ÌìÉú¹þÏ£Öµ£¬Ç¿¶ÈÆ·¼¶Îª10¡£
±ðµÄ£¬HashÃÅÃ滹ÌṩÁËÆäËûһЩҪÁ죬ÀýÈ磺ʹÓÃSHA256¹þÏ£Ëã·¨¾ÙÐйþÏ£¼ÓÃÜ¡£
$hashed_password = Hash::make($password, ['rounds' => 5000, 'algorithm' => 'sha256']);
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬rounds²ÎÊýÓÃÓÚÖ¸¶¨¹þÏ£ÖµµÄÅÌËãÃܶȣ¬algorithm²ÎÊýÓÃÓÚÖ¸¶¨¹þÏ£Ëã·¨¡£
Îå¡¢×ܽá
ÔÚLaravel¿ò¼ÜÖУ¬Óû§ÃÜÂë¹þÏ£»¯ÊÇÒ»ÏîºÜÊÇÖ÷ÒªµÄÇå¾²²½·¥¡£Í¨¹ý¹þÏ£Ëã·¨£¬¿ÉÒÔ½«Óû§ÃÜÂëת»¯Îª²»¿ÉÄæµÄ¹þÏ£Öµ´æ´¢ÔÚÊý¾Ý¿âÖУ¬°ü¹ÜÓû§Òþ˽µÄÇå¾²¡£Laravel¿ò¼ÜÖеÄHashÃÅÃæÌṩÁ˺ÜÊÇÀû±ãµÄÒªÁìÀ´ÊµÏÖ¹þÏ£¼ÓÃܲÙ×÷£¬¿ª·¢Õß¿ÉÒÔƾ֤²î±ðµÄÒªÇóÀ´Ñ¡ÔñÏà¹Ø²ÎÊýºÍ¹þÏ£Ëã·¨£¬Ìá¸ßÃÜÂëµÄÇå¾²ÐÔ¡£
ÒÔÉϾÍÊÇlaravel Óû§ÃÜÂëÔõôÄð³É¹þÏ£ÖµµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡