User registration and authentication using hashed passwords
Nope, it is not safe. You can refer to the following article thet explains why you shouldn't use SHA-family hashing and required to use password_hash() instead. Beside other things, it means that salt field should be removed, and password field should be varchar(255).

To soften the pill, I've got the reference code to check the hashed passsword.

There is one more issue which is connected to security: wherever an error occurs, you are echoing it right in the hands of a potential hacker, revealing a lot of sensitive information about your software, database structure, etc. You should never ever be doing things like  echo "Error: " . $e-&gt;getMessage();! For more info refer to my article on the basics of PHP error reporting

Everything else is rather good, save for peculiar code formatting and unnecessary WHILE statement. When you expect just a single row, there is no need to run a while loop. Just fetch your row right away.

Also, it does no good to duplicate the database connection code. Store it in a file and just include wherever needed.

So the refactored version would be like

db.php:

&lt;?php

$servername = "localhost";
$username = "whatever";
$password = "whatever";
$dbname = "whatever";
$charset = 'utf8mb4';

$options = [
    PDO::ATTR_ERRMODE            =&gt; PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   =&gt; false,
];
$dsn = "mysql:host=$servername;dbname=$dbname;charset=$charset";
try {
     $db = new PDO($dsn, $username, $password, $options);
} catch (\PDOException $e) {
     throw new \PDOException($e-&gt;getMessage(), (int)$e-&gt;getCode());
}


register.php

require 'db.php';
$hashpsw = password_hash($_POST["providedpass"],);

$stmt = $db-&gt;prepare("INSERT INTO users (username, password, level) VALUES (?,?,?)");
$stmt-&gt;execute(array($_POST["usrnm"], $hashpsw, 1));
echo "USER CREATED";


auth.php:

require 'db.php';
$stmt = $db-&gt;prepare("SELECT * FROM users WHERE username = ?");
$stmt-&gt;execute([$_POST['usrnm']]);
$user = $stmt-&gt;fetch();

if ($user &amp;&amp; password_verify($_POST['providedpass'], $user['password']))
{
    echo "FOUND USER";
}