tailieunhanh - PHP and MySQL Web Development - P106

PHP and MySQL Web Development - P106: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | Implementing User Authentication 497 Listing Continued to make it a slightly better password srand double microtime 1000000 rand_number rand 0 999 new_password . rand_number set user s password to this in database or return false if conn db_connect return false result mysql_query update user set passwd password new_password where username username if result return false not changed else return new_password changed successfully This function generates its random password by getting a random word from a dictionary using the get_random_word function and suffixing it with a random number between 0 and get_random_word function is also in the library. This function is shown in Listing . Listing The get_random_word Function from This Function Gets a Random Word from the Dictionary for Use in Generating Passwords function get_random_word min_length max_length grab a random word from dictionary between the two lengths and return it generate a random word word remember to change this path to suit your system dictionary usr dict words the ispell dictionary fp fopen dictionary r if fp return false size filesize dictionary go to a random location in dictionary srand double microtime 1000000 rand_location rand 0 size fseek fp rand_location get the next whole word of the right length in the file while strlen word min_length strlen word max_length strstr word 498 Chapter 24 Building User Authentication and Personalization Listing Continued if feof fp fseek fp 0 if at end go to start word fgets fp 80 skip first word as it could be partial word fgets fp 80 the potential password word trim word trim the trailing n from fgets return word To work this function needs a dictionary. If you are using a UNIX system the built-in spell checker ispell comes with a dictionary of words typically located at usr dict words as it is here or at usr share dict words. If you don t find it in one of these places on most systems you will

TỪ KHÓA LIÊN QUAN