A simple PHP login system I'm super new to PHP and I'm trying to get a functional login system together. This is the code I have:

class/user.php

&lt;?php
 class Users {
     public $username = null;
     public $password = null;
     public $salt = "Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w";

     public function __construct( $data = array() ) {
         if( isset( $data['username'] ) ) $this-&gt;username = stripslashes( strip_tags( $data['username'] ) );
         if( isset( $data['password'] ) ) $this-&gt;password = stripslashes( strip_tags( $data['password'] ) );
     }

     public function storeFormValues( $params ) {
        //store the parameters
        $this-&gt;__construct( $params ); 
     }

     public function userLogin() {
         $success = false;
         try{
            $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); 
            $con-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
            $sql = "SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1";

            $stmt = $con-&gt;prepare( $sql );
            $stmt-&gt;bindValue( "username", $this-&gt;username, PDO::PARAM_STR );
            $stmt-&gt;bindValue( "password", hash("sha256", $this-&gt;password . $this-&gt;salt), PDO::PARAM_STR );
            $stmt-&gt;execute();

            $valid = $stmt-&gt;fetchColumn();

            if( $valid ) {
                $success = true;
            }

            $con = null;
            return $success;
         }catch (PDOException $e) {
             echo $e-&gt;getMessage();
             return $success;
         }
     }

     public function register() {
        $correct = false;
            try {
                $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
                $con-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
                $sql = "INSERT INTO users(username, password) VALUES(:username, :password)";

                $stmt = $con-&gt;prepare( $sql );
                $stmt-&gt;bindValue( "username", $this-&gt;username, PDO::PARAM_STR );
                $stmt-&gt;bindValue( "password", hash("sha256", $this-&gt;password . $this-&gt;salt), PDO::PARAM_STR );
                $stmt-&gt;execute();
                return "Registration Successful &lt;br/&gt; &lt;a href='index.php'&gt;Login Now&lt;/a&gt;";
            }catch( PDOException $e ) {
                return $e-&gt;getMessage();
            }
     }

 }

?&gt;


login.php

&lt;?php 
    include_once("config.php");
?&gt;
&lt;?php if( !(isset( $_POST['login'] ) ) ) { ?&gt;
    &lt;form method="post" action=""&gt;
        &lt;input type="text" maxlength="30" required autofocus name="username" /&gt;
        &lt;input type="password" maxlength="30" required name="password" /&gt;
        &lt;input type="submit" name="login" value="Log me in" /&gt;
    &lt;/form&gt;
&lt;?php 
} else {
    $usr = new Users;
    $usr-&gt;storeFormValues( $_POST );

    if( $usr-&gt;userLogin() ) {
        echo "Welcome"; 
    } else {
        echo "Incorrect Username/Password"; 
    }
}
?&gt;


register.php

&lt;?php 
    include_once("config.php");
?&gt;

&lt;?php if( !(isset( $_POST['register'] ) ) ) { ?&gt;
    &lt;form method="post"&gt;
        &lt;input type="text" id="usn" maxlength="30" required autofocus name="username" /&gt;
        &lt;input type="password" id="passwd" maxlength="30" required name="password" /&gt;
        &lt;input type="password" id="conpasswd" maxlength="30" required name="conpassword" /&gt;
        &lt;input type="submit" name="register" value="Register" /&gt;
    &lt;/form&gt;

&lt;?php 
} else {
    $usr = new Users;
    $usr-&gt;storeFormValues( $_POST );

    if( $_POST['password'] == $_POST['conpassword'] ) {
        echo $usr-&gt;register($_POST);    
    } else {
        echo "Password and Confirm password not match"; 
    }
}
?&gt;


I am really keen to know how this code is structured, as I used information from several different tutorials combined to create it. Any input would be appreciated.
Data Handling &amp; Security

You use prepared statements, which protects you from SQL injection, which is good. However, the way you handle passwords could be improved to increase security.

It's not a good idea to semi-randomly apply sanitation functions to user input as it results in dirty data. 

stripslashes for example really only makes sense when magic quotes is enabled, so you should check that first (and then only strip the slashes in some init file, not every time you access GET). For example, if a user has a password like this: a\'b\\c\'d, stripping slashes reduces the password length from 9 to 6 characters. 

Same problem with strip_tags, only much worse. If my password is a&lt;super$secure!password, now my password is a.

You also don't need strip_tags. As XSS protection it's not sufficient anyways (and definitely not needed for passwords, which aren't echoed); You should HTML-encode data when echoing it instead.

There's also really no need to have a length restriction on the password, especially not one that is shorter than what your hashing algorithm allows.

Hashing

Simple sha is really not good enough anymore, as it's too fast. Use bcrypt instead.

Error Handling

Don't echo database error messages directly to the enduser. They won't know what to do with it, and it may provide attackers with information or enable some forms of attacks (such as error based SQL injection). 

It's also not a good idea to echo anything in a function, as side-effects like that make it harder to reuse.

Structure

I think your structure is pretty clean, and your code easy to read. Just a couple of small points:

storeFormValues doesn't seem to have any purpose. I wouldn't call the constructor inside a function of the same class, but just use it directly. 

I would also not pass a magic array to the constructor, as it's hard to use and reuse (I have to guess how the array must be build and what it must contain, and I have to use the pre-defined array keys).

Instead, just change your constructor to __construct($username, $password). This increases clarity and reduces future bugs.

Misc


remove unused variables such as $correct.
comments such as //store the parameters are not really needed as they don't add any information.
same things should be named in the same way to avoid confusion. For example, registering and logging in are quite similar. But the names userLogin and register are constructed differently. Just use login and register.