Not authenticating users PHP MySQL
<p>Am trying to figure out why this code is not authenticating users, a wrong combination of username and password gives a user access. Where am I going wrong? Am still a newbie, any help? also, a suggestion on how to encrypt the password, MD5, SHA etc, which is best?</p>

<pre><code>&lt;form class="login-form" action="login.php" method="post"&gt;
    &lt;input type="text" placeholder="username" name="username"/&gt;
    &lt;input type="password" placeholder="password" name="password"/&gt;
    &lt;button type="submit" name="login" value="login"&gt;login&lt;/button&gt;
    &lt;p class="message"&gt;Not registered? &lt;a href="#"&gt;Create anaccount&lt;/a&gt;&lt;/p&gt;
&lt;/form&gt;
</code></pre>

<p>

<pre><code>if (isset($_POST['login'])) {
    include_once("db.php");
    $username = stripslashes($username);
    $password = stripslashes($password);
    $sql = "SELECT * FROM users WHERE username='$username' LIMIT 1";
    $query = mysql_query($sql);
    $row = mysql_fetch_array($query);
    $id = ['id'];
    $db_password = $row['password'];
    if ($password == $password) {
        $_SESSION['username'] = $username;
        $_SESSION['id'] = $id;
        header("Location: index.php");
    } else {
        echo "You have entered invalid credentials.";
    }
}
</code></pre>