Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('DB_NAME','login');
- define('DB_SERVER','localhost');
- define('DB_USERNAME','root');
- define('DB_PASSWORD','');
- class User{
- $dbConn = new PDO("mysql:host=".DB_SERVER.";dbname=".DB_NAME,DB_USERNAME,DB_PASSWORD);
- $dbConn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
- public function Login($name, $password){
- if(!empty($name) && !empty($password)){
- $statement = $dbConn->prepare("select * from users where name=? and password=?");
- $statement->bindParam(1, $name);
- $statement->bindParam(2, $password);
- $statement->execute();
- if($statement->rowCount() == 1){
- echo "User verified, Access granted.";
- }else{
- echo "Incorrect username or password";
- }
- }else{
- echo "Please enter username and password";
- }
- }
- }
- ?>
- <?php
- include_once('user.php');
- if(isset($_POST['submit'])){
- $name = $_POST['user'];
- $password = $_POST['password'];
- $object = new User();
- $object->Login($name, $password);
- }
- ?>
- <html>
- <head>
- </head>
- <body>
- <form method="post" action="index.php">
- Username: <input type="text" name="user">
- Password: <input type="text" name="password">
- <input type="submit" name="submit" value="Login">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement