While the other posters are right, i think a specific answer is being sought so here goes.
forgot password function can be implemented by using two columns related to the user id. one column is a random string, which can be of arbitrary length, and other the date time. When the user indicates that they have forgotten their password, you generate the random string and update this record with the string and the current date time. you then send an email to their registered email id with a url that has the random string. When that url is opened, you will check if the random string exists in your tables and if it has not been expired. you will check the current date time and the date time on which the string was generated, and you will have your own policy for determining what is the longest you will wait. typically 3 days is enough. if the link is expired, the forgot password will have to be started again. if the link is not expired, you will note the user id for which the string was generated and you will ask the user to enter their username and new password two times. the username has to match the userid for which the string was generated, and the two passwords be the same. you will then update the users password with the md5 hash of the new password.
the reason you dont want to generate a new password is because if the user recalls the password, they can still log in, even while their forgot password is in process.