optimize the function of resetting password