 <p>You should just let <code>GetPassword()</code> return <code>null</code> if the password isn't found. The next problem though is that <code>CompareStringToHash()</code> will fail if you pass in a null password, so instead of</p> <pre><code> bool isSame = hasher.CompareStringToHash(txtPassword.Text, hashedPassword); if (isSame==false) { MessageBox.Show("Invalid UserName or Password"); } </code></pre> <p>You do</p> <pre><code> if (hashedPassword == null || hasher.CompareStringToHash(txtPassword.Text, hashedPassword) { MessageBox.Show("Invalid UserName or Password"); } </code></pre> <p>If <code>hashedPassword</code> is <code>null</code> the <code>if</code> statement will be exited before it tries to execute the <code>CompareStringToHash()</code> so you won't get an exception. <code>CompareStringToHash()</code> will only execute if <code>hashedPassword</code> is not <code>null</code>. Then provided you've stored a valid string (which you will have because you are creating it will Encrypto) it should all work - and without a lot of messy <code>if</code> statements :o)</p>