Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- html>
- <body>
- <?php
- function Login()
- {
- if(empty($_POST['username']))
- {
- echo "UserName is empty!";
- return false;
- }
- if(empty($_POST['password']))
- {
- echo "Password is empty!";
- return false;
- }
- $username = trim($_POST['username']);
- $password = trim($_POST['password']);
- if(!$this->CheckLoginInDB($username,$password))
- {
- return false;
- }
- session_start();
- $_SESSION[$this->GetLoginSessionVar()] = $username;
- return true;
- }
- function DBLogin()
- {
- $ligacao= mysql_connect("localhost","root","");
- if(!$ligacao){
- echo "<p>Falha na ligação à Base de dados.";
- exit;
- }
- mysql_select_db("book",$ligacao);
- }
- function CheckLoginInDB($username,$password)
- {
- if(!$this->DBLogin())
- {
- $this->HandleError("Database login failed!");
- return false;
- }
- $username = $this->SanitizeForSQL($username);
- $pwdmd5 = md5($password);
- $qry = "Select name, email from $this->tablename ".
- " where username='$username' and password='$password' ";
- $result = mysql_query($qry,$this->connection);
- if(!$result || mysql_num_rows($result) <= 0)
- {
- $this->HandleError("Error logging in. ".
- "The username or password does not match");
- return false;
- }
- return true;
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment