I got this working for me ... On the internet there are many solution for this but they don't explain this in details on how we can achieve this correctly ... So I am posting my answer for those who are new to this like me.
In my question I explained that I am creating a external script that will be using joomla site's database which I have already up and running ... Please note that the external script that I am writing and the joomla site, both are hosted on the same server but are in separate directories. Below is the code that I have used ... this code is available on most of the joomla forums and even on stack overflow but I have slightly modified it according my needs but it will work on any script.
define('_JEXEC', 1);
define('JPATH_BASE', '/Users/faisalhussain/Sites/joomla/');
require_once JPATH_BASE . 'includes/defines.php';
require_once JPATH_BASE . 'includes/framework.php';
Most answers I came accross don't explain that in order for the above code to work you need to have a working joomla installation ... As I mentioned before that my script and my joomla site are on the same server but in separate directories so I had to provide a absolute path to my joomla installation define('JPATH_BASE', '/Users/faisalhussain/Sites/joomla/');
... but if you are creating a script that is within the root of joomla then you can use relative path. After implementing the above code now I can use any method of any joomla class within my external script. Hope this helps anyone who is in need to use joomla framework outside of joomla.
verifyPassword
in the file[JOOMLA_ROOT]/libraries/joomla/user/helper.php
.