Compare password in WordPress always return false
<p>I want to insert new user in WordPress by coding and then compare username &amp; 
password. I tried to insert user name and password in two ways.</p>

<p><strong>1</strong></p>

<p>Insert new user code (Table - wp_users)</p>

<pre><code>$email = $_POST['txtEmail'];
$userName = $_POST['txtUserName'];//Sahil
$password = $_POST['txtPassword'];//1212
$hash_value = password_hash($password, PASSWORD_BCRYPT);
$user_id = wp_create_user( $userName, $hash_value, $email);
</code></pre>

<p><strong>2</strong></p>

<p>Tried to insert password in another way</p>

<pre><code>$settings = array('cost' =&gt; 10, 'salt' =&gt; 'rSq.2M7Ikc.QPhVtYlp1Nu');
$hash_value = password_hash($password, PASSWORD_BCRYPT, $settings);
$user_id = wp_create_user( $userName, $hash_value, $email);
</code></pre>

<p>I didn't add code to check username &amp; email exists in table. Above code is working properly and new user is being added in wp_users table and password is being stored in hash format. Ex. $P$BgynwP/kZuQu5p/SAU/dTMA19sbJs3/</p>

<p>I tried to compare it by two function,  but it always return false.</p>

<p><strong>1</strong></p>

<pre><code>$userName = $_POST['txtUserName'];//Sahil
$password = $_POST['txtPassword'];//1212

$user = get_user_by( 'login', $userName );
$result = wp_check_password( $password, $user-&gt;user_pass, $user-&gt;ID);
if($result){
        echo 'Correct';
    }else{
        echo 'Wrong'; //Always return wrong
    }
</code></pre>

<p><strong>2</strong></p>

<pre><code>$userName = $_POST['txtUserName'];//Sahil
$password = $_POST['txtPassword'];//1212
$user = get_user_by( 'login', $userName );
$isPasswordCorrect = password_verify($password, $user-&gt;user_pass);
if($isPasswordCorrect){
        echo 'Correct';
    }else{
        echo 'Wrong'; //Always return wrong.
    }
</code></pre>

<p>Also tried - </p>

<pre><code>var_dump(password_verify($password, $user-&gt;user_pass));
</code></pre>

<p>But it still return false.</p>

<p>Let me know, If there is any mistake in my code while comparing password or technique is wrong to do this. </p>

<p>Thanks</p>