Latest Post
Tampilkan postingan dengan label login. Tampilkan semua postingan
Tampilkan postingan dengan label login. Tampilkan semua postingan

PHP script for Login with Facebook and Twitter

Written By Unknown on Selasa, 20 September 2011 | 10.21

Facebook and Twitter have become large in the social network world and both networks offering oAuth support. We developed a system to login with Twitter and Facebook. Nowadays web users not interested to filling the big registration forms. This script helps you to avoid registration forms, It’s is very useful and simple to integrate.



Database

Sample database users table columns id, email, oauth_uid, oauth_provider and username.

CREATE TABLE users
(
id INT PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(70), 
oauth_uid int(11),
oauth_provider VARCHAR(100),
username VARCHAR(100), 
twitter_oauth_token VARCHAR(200), 
twitter_oauth_token_secret VARCHAR(200) 
);

The tutorial contains three folders called facebook,twitter and config with PHP files.

facebook //Facebook OAUTH library 
twitter //Twitter OAUTH library 
config
-- functions.php 
-- dbconfig.php //Database connection 
-- fbconfig.php //Facebook API connection
-- twconfig.php //Twitter API connection
index.php
home.php
login-twitter.php
login-facebook.php
getTwitterData.php


Facebook Setup

You have to create a application. Facebook will provide you app id and app secret id, just modify following code 

fcconfig.php

<?php
define('APP_ID', 'Facebook APP ID');
define('APP_SECRET', 'Facebook Secret ID');
?>

Twitter Setup

Create a twitter application click here. Some like Facebook Twitter provide you consumer key amd consumer secret key using these modify following code.

twconfig.php

<?php
define('YOUR_CONSUMER_KEY', 'Twitter Key');
define('YOUR_CONSUMER_SECRET', 'Twitter Secret Key');
?>

dbconfig.php

Database configuration file. 

<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'User Name');
define('DB_PASSWORD', 'Password');
define('DB_DATABASE', 'DATABASE');
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
?>

login-twitter.php

In root directory find out the below line at login-twitter.php code and replace yourwebsite. 

$request_token= $twitteroauth->getRequestToken('http://yourwebsite.com/getTwitterData.php');

index.php

If you want to modify your web project existing login or index pages, just use following code. 

<?php
session_start();
if (isset($_SESSION['id'])) {
// Redirection to login page twitter or facebook
header("location: home.php");
}
if (array_key_exists("login", $_GET)) 
{
$oauth_provider = $_GET['oauth_provider'];
if ($oauth_provider == 'twitter')
{
header("Location: login-twitter.php");
}
else if ($oauth_provider == 'facebook')
 {
header("Location: login-facebook.php");
}
}
?>
//HTML Code
<a href="?login&oauth_provider=twitter">Twitter_Login</a>
<a href="?login&oauth_provider=facebook">Facebook_Login</a>

If any queries please comment here. 

Blocking access to the login page after three unsuccessful login attempts

Written By Unknown on Sabtu, 13 Maret 2010 | 00.12


Sometimes you need to add an extra protection to password-protected website. This article explains how access to the login page can be restricted after three unsuccessful login attempts. This schema uses visitors IP address to store log attempts in the database and block access to login feature for 30 minutes after third unsuccessful attempt.
There are a number of reasons to restrict access. One reason is security. Quite often users try to guess login and password combination to get unauthorized access to the system. Another reason is extra load on server.
So let's start. At first you need to create a new table in your database to store information about login attempts from a certain computer. SQL script creating such table in MySQL Server will be the following. For other databases it will slightly differ.
CREATE TABLE `LoginAttempts`
(
`IP` VARCHAR( 20 ) NOT NULL ,
`Attempts` INT NOT NULL ,
`LastLogin` DATETIME NOT NULL
)

It is assumed that you have already had an authorization page. Otherwise you can create it using PHP, SSI, and similar languages. There are no major difficulties in writing this program (script).
Authorization page should work with two tables: one table where information about registered users is stored and the other one where unsuccessful login attempts are listed.
Before verifying entered data, system has to check if the user exceeded attempts limit or not. If in the LoginAttempts table there are more than two records correspondent to one IP address, then error message will appear saying that access is blocked for a certain period of time. You can set time period at your discretion. Depending on your security policy it can vary from 1 minute to 24 hours or more. In the following example access will be blocked for 30 minutes.
<?php
function confirmIPAddress($value) {

  $q = "SELECT attempts, (CASE when lastlogin is not NULL and DATE_ADD(LastLogin, INTERVAL ".TIME_PERIOD.
  " MINUTE)>NOW() then 1 else 0 end) as Denied FROM ".TBL_ATTEMPTS." WHERE ip = '$value'";

  $result = mysql_query($q, $this->connection);
  $data = mysql_fetch_array($result);

  
//Verify that at least one login attempt is in database 

  if (!$data) {
    return 0;
  }
  if ($data["attempts"] >= ATTEMPTS_NUMBER)
  {
    if($data["Denied"] == 1)
    {
      return 1;
    }
    else
    {
      $this->clearLoginAttempts($value);
      return 0;
    }
  }
  return 0;
}

function addLoginAttempt($value) {
   //Increase number of attempts. Set last login attempt if required.

   $q = "SELECT * FROM ".TBL_ATTEMPTS." WHERE ip = '$value'";
   $result = mysql_query($q, $this->connection);
   $data = mysql_fetch_array($result);
  
   if($data)
   {
     $attempts = $data["attempts"]+1;        

     if($attempts==3) {
       $q = "UPDATE ".TBL_ATTEMPTS." SET attempts=".$attempts.", lastlogin=NOW() WHERE ip = '$value'";
       $result = mysql_query($q, $this->connection);
     }
     else {
       $q = "UPDATE ".TBL_ATTEMPTS." SET attempts=".$attempts." WHERE ip = '$value'";
       $result = mysql_query($q, $this->connection);
     }
   }
   else {
     $q = "INSERT INTO ".TBL_ATTEMPTS." (attempts,IP,lastlogin) values (1, '$value', NOW())";
     $result = mysql_query($q, $this->connection);
   }
}

function clearLoginAttempts($value) {
  $q = "UPDATE ".TBL_ATTEMPTS." SET attempts = 0 WHERE ip = '$value'";
  return mysql_query($q, $this->connection);
}
?>
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger