Advertisement
MSupian

Contoh Form Login & Register

May 26th, 2016
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.83 KB | None | 0 0
  1. <?php
  2. require'../lib/config.php';
  3.  
  4. @$users = $_SESSION['login'];
  5. $mysqli->query("SELECT username FROM users WHERE username = '$users'");
  6. $validation = $mysqli->numRows();
  7.  
  8. if($validation > 0 && $users && !($_GET['page'])) {
  9.     Redirect($setting->url."/dashboard");
  10. }
  11.  
  12. if($_GET['page'] == 'Login' || $_GET['page'] == '') {?>
  13. <!DOCTYPE html>
  14. <html lang="en">
  15. <head>
  16.     <meta charset="<?php echo $setting->charset;?>">
  17.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  18.     <meta name="description" content="<?php echo $setting->description;?>/">
  19.     <meta name="author" content="M-Supian.ID">
  20.     <meta name="keyword" content="<?php echo $setting->keywords;?>/">
  21.     <link rel="shortcut icon" href="<?php echo $setting->img;?>/favicon.png">
  22.     <title><?php echo $setting->title;?> | Signin</title>
  23.     <!-- Bootstrap core CSS -->
  24.     <link href="<?php echo $setting->css;?>/bootstrap.min.css" rel="stylesheet">
  25.     <link href="<?php echo $setting->css;?>/bootstrap-reset.css" rel="stylesheet">
  26.     <!--external css-->
  27.     <link href="<?php echo $setting->assets;?>/font-awesome/css/font-awesome.css" rel="stylesheet" />
  28.     <!-- Custom styles for this template -->
  29.     <link href="<?php echo $setting->css;?>/style.css" rel="stylesheet">
  30.     <link href="<?php echo $setting->css;?>/style-responsive.css" rel="stylesheet" />
  31.     <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
  32.     <!--[if lt IE 9]>
  33.     <script src="<?php echo $setting->js;?>/html5shiv.js"></script>
  34.     <script src="<?php echo $setting->js;?>/respond.min.js"></script>
  35.     <![endif]-->
  36. </head>
  37.   <body class="login-body">
  38.     <div class="container">
  39.       <form class="form-signin" method="POST">
  40.         <h2 class="form-signin-heading">sign in now</h2>
  41.         <div class="login-wrap">
  42.           <?php Message();?>
  43.             <input type="text" class="form-control" name="username" placeholder="Username" autofocus>
  44.             <input type="password" class="form-control" name="password" placeholder="Password">
  45.             <label class="checkbox">
  46.                 <input type="checkbox" name="rememberme"> Remember me
  47.                 <span class="pull-right">
  48.                     <a href="<?php echo $setting->url."/forgot";?>"> Forgot Password?</a>
  49.                 </span>
  50.             </label>
  51.             <button class="btn btn-lg btn-login btn-block" type="submit" name="signin">Sign in</button>
  52.             <div class="registration">
  53.                 Don't have an account yet?
  54.                 <a class="" href="signup">
  55.                     Create an account
  56.                 </a>
  57.             </div>
  58.         </div>
  59.       </form>
  60.     </div>
  61.     <!-- js placed at the end of the document so the pages load faster -->
  62.     <script src="<?php echo $setting->js;?>/jquery.js"></script>
  63.     <script src="<?php echo $setting->js;?>/bootstrap.min.js"></script>
  64.   </body>
  65. </html>
  66.  
  67. <?php } /*
  68. |--------------------------------------------------------------------------
  69. |   GET login
  70. |--------------------------------------------------------------------------
  71. */
  72.  
  73. else if ($_GET['page'] == 'Register') {?>
  74.  
  75. <!DOCTYPE html>
  76. <html lang="en">
  77. <head>
  78.     <meta charset="<?php echo $setting->charset;?>">
  79.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  80.     <meta name="description" content="<?php echo $setting->description;?>/">
  81.     <meta name="author" content="M-Supian.ID">
  82.     <meta name="keyword" content="<?php echo $setting->keywords;?>/">
  83.     <link rel="shortcut icon" href="<?php echo $setting->img;?>/favicon.png">
  84.     <title><?php echo $setting->title;?> | Signup</title>
  85.     <!-- Bootstrap core CSS -->
  86.     <link href="<?php echo $setting->css;?>/bootstrap.min.css" rel="stylesheet">
  87.     <link href="<?php echo $setting->css;?>/bootstrap-reset.css" rel="stylesheet">
  88.     <!--external css-->
  89.     <link href="<?php echo $setting->assets;?>/font-awesome/css/font-awesome.css" rel="stylesheet" />
  90.     <!-- Custom styles for this template -->
  91.     <link href="<?php echo $setting->css;?>/style.css" rel="stylesheet">
  92.     <link href="<?php echo $setting->css;?>/style-responsive.css" rel="stylesheet" />
  93.     <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
  94.     <!--[if lt IE 9]>
  95.     <script src="js/html5shiv.js"></script>
  96.     <script src="js/respond.min.js"></script>
  97.     <![endif]-->
  98. </head>
  99.   <body class="login-body">
  100.     <div class="container">
  101.       <form class="form-signin" method="POST">
  102.         <h2 class="form-signin-heading">registration now</h2>
  103.         <div class="login-wrap">
  104.             <p> Enter your account details below</p>
  105.             <?php Message();?>
  106.             <input type="text" class="form-control" name="username" placeholder="User Name" autofocus required>
  107.             <input type="text" class="form-control" name="email" placeholder="Email" autofocus>
  108.             <input type="password" class="form-control" name="password" placeholder="Password" require>
  109.             <input type="password" class="form-control" name="retype" placeholder="Re-type Password" require>
  110.             <button class="btn btn-lg btn-login btn-block" type="submit" name="signup">Submit</button>
  111.             <div class="registration">
  112.                 Already Registered.
  113.                 <a class="" href="signin">
  114.                     Login
  115.                 </a>
  116.             </div>
  117.         </div>
  118.       </form>
  119.     </div>
  120.     <!-- js placed at the end of the document so the pages load faster -->
  121.     <script src="<?php echo $setting->js;?>/jquery.js"></script>
  122.     <script src="<?php echo $setting->js;?>/bootstrap.min.js"></script>
  123.   </body>
  124. </html>
  125. <?php }
  126. else if($_GET['page'] == "Lock") {
  127.           $_SESSION['unlock'] = "False";
  128.           if(!$users) {
  129.               Redirect($setting->url."/signin");
  130.           }?>
  131. <!DOCTYPE html>
  132. <html lang="en">
  133. <head>
  134.     <meta charset="<?php echo $setting->charset;?>">
  135.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  136.     <meta name="description" content="<?php echo $setting->description;?>/">
  137.     <meta name="author" content="M-Supian.ID">
  138.     <meta name="keyword" content="<?php echo $setting->keywords;?>/">
  139.     <link rel="shortcut icon" href="<?php echo $setting->img;?>/favicon.png">
  140.     <title><?php echo $setting->title;?> | Lock Screen</title>
  141.     <!-- Bootstrap core CSS -->
  142.     <link href="<?php echo $setting->css;?>/bootstrap.min.css" rel="stylesheet">
  143.     <link href="<?php echo $setting->css;?>/bootstrap-reset.css" rel="stylesheet">
  144.     <!--external css-->
  145.     <link href="<?php echo $setting->assets;?>/font-awesome/css/font-awesome.css" rel="stylesheet" />
  146.     <!-- Custom styles for this template -->
  147.     <link href="<?php echo $setting->css;?>/style.css" rel="stylesheet">
  148.     <link href="<?php echo $setting->css;?>/style-responsive.css" rel="stylesheet" />
  149.     <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
  150.     <!--[if lt IE 9]>
  151.     <script src="<?php echo $setting->js;?>/html5shiv.js"></script>
  152.     <script src="<?php echo $setting->js;?>/respond.min.js"></script>
  153.     <![endif]-->
  154. </head>
  155. <body class="lock-screen" onload="startTime()">
  156.     <div class="lock-wrapper">
  157.         <div id="time"></div>
  158.         <div class="lock-box text-center">
  159.             <img src="<?php echo $setting->img;?>/follower-avatar.jpg" alt="lock avatar"/>
  160.             <h1><?php echo $_SESSION['login'];?></h1>
  161.             <span class="locked">Locked</span>
  162.             <?php Message();?>
  163.             <form role="form" class="form-inline" method="POST" action="">
  164.                 <div class="form-group col-lg-12">
  165.                     <input type="password" placeholder="Password" class="form-control" name="password" required>
  166.                     <button class="btn btn-lock" type="submit" name="unlock">
  167.                        Unlock <i class="fa fa-unlock"></i>
  168.                     </button>
  169.                 </div>
  170.             </form>
  171.         </div>
  172.     </div>
  173.     <!-- js placed at the end of the document so the pages load faster -->
  174.     <script src="<?php echo $setting->js;?>/jquery.js"></script>
  175.     <script src="<?php echo $setting->js;?>/bootstrap.min.js"></script>
  176.     <script>
  177.         function startTime() {
  178.             var today=new Date();
  179.             var h=today.getHours();
  180.             var m=today.getMinutes();
  181.             var s=today.getSeconds();
  182.             // add a zero in front of numbers<10
  183.             m=checkTime(m);
  184.             s=checkTime(s);
  185.             document.getElementById('time').innerHTML=h+":"+m+":"+s;
  186.             t=setTimeout(function(){startTime()},500);
  187.         }
  188.  
  189.         function checkTime(i) {
  190.             if (i<10){
  191.                 i="0" + i;
  192.             }
  193.             return i;
  194.         }
  195.     </script>
  196. </body>
  197. </html>
  198.  
  199. <?php } else if($_GET['page'] == "Forgot") { ?>
  200. <!DOCTYPE html>
  201. <html lang="en">
  202. <head>
  203.     <meta charset="<?php echo $setting->charset;?>">
  204.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  205.     <meta name="description" content="<?php echo $setting->description;?>/">
  206.     <meta name="author" content="M-Supian.ID">
  207.     <meta name="keyword" content="<?php echo $setting->keywords;?>/">
  208.     <link rel="shortcut icon" href="<?php echo $setting->img;?>/favicon.png">
  209.     <title><?php echo $setting->title;?> | Signin</title>
  210.     <!-- Bootstrap core CSS -->
  211.     <link href="<?php echo $setting->css;?>/bootstrap.min.css" rel="stylesheet">
  212.     <link href="<?php echo $setting->css;?>/bootstrap-reset.css" rel="stylesheet">
  213.     <!--external css-->
  214.     <link href="<?php echo $setting->assets;?>/font-awesome/css/font-awesome.css" rel="stylesheet" />
  215.     <!-- Custom styles for this template -->
  216.     <link href="<?php echo $setting->css;?>/style.css" rel="stylesheet">
  217.     <link href="<?php echo $setting->css;?>/style-responsive.css" rel="stylesheet" />
  218.     <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
  219.     <!--[if lt IE 9]>
  220.     <script src="<?php echo $setting->js;?>/html5shiv.js"></script>
  221.     <script src="<?php echo $setting->js;?>/respond.min.js"></script>
  222.     <![endif]-->
  223. </head>
  224.   <body class="login-body">
  225.     <div class="container">
  226.       <form class="form-signin" method="POST">
  227.         <h2 class="form-signin-heading">Forgot Password</h2>
  228.         <div class="login-wrap">
  229.             <input type="text" class="form-control" name="username" placeholder="Username" autofocus>
  230.             <button class="btn btn-lg btn-login btn-block" type="submit" name="forgot">Forgot</button>
  231.             <div class="registration">
  232.                 Don't have an account yet?
  233.                 <a class="" href="signup">
  234.                     Create an account
  235.                 </a>
  236.             </div>
  237.         </div>
  238.       </form>
  239.     </div>
  240.     <!-- js placed at the end of the document so the pages load faster -->
  241.     <script src="<?php echo $setting->js;?>/jquery.js"></script>
  242.     <script src="<?php echo $setting->js;?>/bootstrap.min.js"></script>
  243.   </body>
  244. </html>
  245. <?php }
  246. /*
  247. |--------------------------------------------------------------------------
  248. |   Jangan dirubah bila anda tidak mengerti PHP
  249. |--------------------------------------------------------------------------
  250. */
  251.  
  252. @$username = Clear($_POST['username']);
  253. @$email    = Clear($_POST['email']);
  254. @$passwd   = $_POST['password'];
  255. @$retype   = $_POST['retype'];
  256. // Encryption Password
  257. @$password = Encrypt($username, $passwd); // result ex: Susan_98e15403b2b1ea5 // Bisa didecrypt ? ntahlah :v
  258.  
  259. /*
  260. |--------------------------------------------------------------------------
  261. |   Proses pendaftaran
  262. |--------------------------------------------------------------------------
  263. */
  264.  
  265.  
  266.  
  267. if(isset($_POST['signup'])) {
  268.  
  269.   if(!strstr($email, "@")) {
  270.     AddMessage_W("Invalid email, please input correctly");
  271.     Redirect();
  272.     exit();
  273.   }
  274.  
  275.   foreach(array(" ", "`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "=", "+", "{", "}", "[", "]", "\\", "|", ";", ":", "<", ">", ",", ".", "?", "/") as $value) {
  276.     if(strstr($_POST['username'], $value)) {
  277.       AddMessage_W("Username should not contain symbol");
  278.       Redirect();
  279.       exit();
  280.     }
  281.   }
  282.  
  283.   if(strlen($_POST['password']) < 5) {
  284.     AddMessage_W("Password length must be at least five letters or more");
  285.     Redirect();
  286.     exit();
  287.   }
  288.  
  289.   // Validasi User & email
  290.   $mysqli->query("SELECT username FROM users WHERE username = '$username'");
  291.   $rowUser  = $mysqli->numRows();
  292.   $mysqli->query("SELECT email FROM users WHERE email = '$email'");
  293.   $rowEmail = $mysqli->numRows();
  294.   if($rowUser > 0) {
  295.     AddMessage_E("Username already used");
  296.   } else if ($rowEmail > 0 ) {
  297.     AddMessage_E("Email already registered");
  298.   } else if ($passwd != $retype) {
  299.     AddMessage_E("Password must match");
  300.   } else {
  301.     // Validasi Referal Code
  302.     $referal = $_SESSION['referal'];
  303.     $mysqli->query("SELECT username FROM users WHERE referral_code = '$referal'");
  304.     $row        = $mysqli->fetchArray();
  305.     $validation = $mysqli->numRows();
  306.     if($validation == 1) {
  307.       $referer = $row['username'];
  308.     }
  309.     // Make Referal Code
  310.     $referral_code  = Random(20);
  311.     // Insert New Account to DB
  312.    
  313.     // Insert Credit
  314.     if($referer) {
  315.       $queryUser = $mysqli->query("INSERT INTO users (id, username, password, email, referral_code, referer, credit) VALUES (NULL, '$username', '$password', '$email', '$referral_code', '$referer', '75') ");
  316.       $queryBonusCredit = $mysqli->query("UPDATE users SET credit = credit + 10 WHERE username = '$referer'");
  317.     } else {
  318.       $queryUser = $mysqli->query("INSERT INTO users (id, username, password, email, referral_code, referer, credit) VALUES (NULL, '$username', '$password', '$email', '$referral_code', '-', '50') ");
  319.     }
  320.     // Finish
  321.     if(($queryUser && $queryBonusCredit) || $queryUser) {
  322.       session_unset($_SESSION['referal']);
  323.       AddMessage_S("Success create new account");
  324.       Redirect($setting->url."/signin");
  325.       exit();
  326.     } else {
  327.       AddMessage_S("Please contact admin");
  328.     }
  329.   }
  330.   Redirect();
  331. }
  332.  
  333. /*
  334. |--------------------------------------------------------------------------
  335. |   Proses Login
  336. |--------------------------------------------------------------------------
  337. */
  338.  
  339. if(isset($_POST['signin'])) {
  340.   // Cek validasi user
  341.   $mysqli->query("SELECT username, email, password, status FROM users WHERE username = '$username' OR email = '$email'");
  342.   $validation     = $mysqli->numRows();
  343.   $fetchArray     = $mysqli->fetchArray();
  344.   if($validation != 1) {
  345.       AddMessage_E("Account is not registered");
  346.   } else if($fetchArray['status'] == "Banned") {
  347.       AddMessage_E("Your account has suspended, please contact admin");
  348.   } else if($fetchArray['password'] != "$password") {
  349.       AddMessage_E("Wrong password");
  350.   }  else {
  351.     if (isset($_POST['rememberme'])) {
  352.       setcookie("username", $username, time() + 60 * 60 * 24 * 100, '/');
  353.     }
  354.     session_start();
  355.     $_SESSION['login'] = $fetchArray['username'];
  356.     $_SESSION['unlock'] = "True";
  357.     Redirect($setting->url);
  358.     exit();
  359.   }
  360.   Redirect();
  361. }
  362.  
  363. /*
  364. --------------------------------------------------------------------------
  365. |   Proses Unlock
  366. |--------------------------------------------------------------------------
  367. */
  368. if(isset($_POST['unlock'])) {
  369.   $username = $_SESSION['login'];
  370.   // Encryption Password
  371.   $password = Encrypt($username, $passwd); // result ex: Susan_98e15403b2b1ea5 // Bisa didecrypt ? ntahlah :v
  372.   // Cek validasi user
  373.   $mysqli->query("SELECT username, password FROM users WHERE username = '$username'");
  374.   $fetchArray     = $mysqli->fetchArray();
  375.   if ($fetchArray['password'] != "$password") {
  376.     AddMessage_E("Wrong password");
  377.   } else {
  378.     session_start();
  379.     $_SESSION['login'] = $fetchArray['username'];
  380.     $_SESSION['unlock'] = "True";
  381.     Redirect("dashboard");
  382.     exit;
  383.   }
  384.   Redirect();
  385. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement