PHP Classes
elePHPant
Icontem

File: examples/two-step-login/register.php

Recommend this page to a friend!
  Classes of Subin Siby  >  Secure PHP Login System  >  examples/two-step-login/register.php  >  Download  
File: examples/two-step-login/register.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Secure PHP Login System
Register and login users using a database via PDO
Author: By
Last change: Follow PSR standards
Formatted code to follow Francium coding standards

Formatted files using [phpfmt](https://github.com/subins2000/phpfmt) to follow Francium [coding standards](https://github.com/FranciumOS/Francium/blob/master/CODING-STANDARDS.md)
Replace spaces indentation with tabs
Date: 2 years ago
Size: 2,962 bytes
 

 

Contents

Class file image Download
<?php
include 'config.php';
?>
<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <div class="content">
            <h1>Register</h1>
            <form action="register.php" method="POST">
                <label>
                    <input name="username" placeholder="Username" />
                </label>
                <label>
                    <input name="email" placeholder="E-Mail" />
                </label>
                <label>
                    <input name="pass" type="password" placeholder="Password" />
                </label>
                <label>
                    <input name="retyped_password" type="password" placeholder="Retype Password" />
                </label>
                <label>
                    <input name="name" placeholder="Name" />
                </label>
                <label>
                    <button name="submit">Register</button>
                </label>
            </form>
            <?php
           
if (isset($_POST['submit'])) {
               
$username = $_POST['username'];
               
$email = $_POST['email'];
               
$password = $_POST['pass'];
               
$retyped_password = $_POST['retyped_password'];
               
$name = $_POST['name'];
                if (
$username == '' || $email == '' || $password == '' || $retyped_password == '' || $name == '') {
                    echo
'<h2>Fields Left Blank</h2>', '<p>Some Fields were left blank. Please fill up all fields.</p>';
                } elseif (!
$LS->validEmail($email)) {
                    echo
'<h2>E-Mail Is Not Valid</h2>', '<p>The E-Mail you gave is not valid</p>';
                } elseif (!
ctype_alnum($username)) {
                    echo
'<h2>Invalid Username</h2>', "<p>The Username is not valid. Only ALPHANUMERIC characters are allowed and shouldn't exceed 10 characters.</p>";
                } elseif (
$password != $retyped_password) {
                    echo
"<h2>Passwords Don't Match</h2>", "<p>The Passwords you entered didn't match</p>";
                } else {
                   
$createAccount = $LS->register($username, $password,
                        array(
                           
'email' => $email,
                           
'name' => $name,
                           
'created' => date('Y-m-d H:i:s'), // Just for testing
                       
)
                    );
                    if (
$createAccount === 'exists') {
                        echo
'<label>User Exists.</label>';
                    } elseif (
$createAccount === true) {
                        echo
"<label>Success. Created account. <a href='login.php'>Log In</a></label>";
                    }
                }
            }
           
?>
<style>
                label{
                    display: block;
                    margin-bottom: 5px;
                }
            </style>
        </div>
    </body>
</html>