Giter VIP home page Giter VIP logo

php-secure-login's Introduction

CyleSoft PHP Secure Login System

It's pretty simple. Uses BLOWFISH ($2y$, specifically) crypt() hashing in PHP 5.3.7+. The purpose behind this was to make a pretty damn good way to store passwords and give the user a unique session token.

Requirements

  • PHP 5.3.7+
  • MySQL

Installation

  1. Set up a new MySQL database, build its tables using user_tables.sql
  2. Rename dbconn_mysql.example.php to dbconn_mysql.php and put the database info in there.
  3. Upload the files to your web server and visit index.php

How it works

  1. User registers using an email address and password (though you could easily swap out email for username).
  2. A unique salt is generated using /dev/urandom via a get_key() function originally found here.
  3. Password is hashed using crypt() $2y$ BLOWFISH hashing, at 12 cost.
  4. New user data is stored in MySQL, yay.
  5. User is presented to log in.
  6. When a user logs in, it looks up their email, and compares passwords based on crypt() functionality.
  7. If the user logs in successfully, they are given a 256-bit key and a 256-bit secret (using get_key(256)) that identifies them.
  8. The session key/secret token is saved via a cookie, which is set to expire in 30 days by default.
  9. When the user accesses a page, PHP looks up their session based on this key.

That's it! Obviously you'd probably want to build in a way for a user to invalidate all of their current sessions and change their password.

Notes

Originally this used /dev/random instead of /dev/urandom, but it got way too slow as /dev/random would run out of entropy. Not sure exactly how to fix that yet, as my server does not have a TRNG to run rng-tools with.

Obviously you'd still want to use SSL to prevent any over-the-wire (or over-the-air) session hijacking and password stealing.

It also features a login flood control mechanism to prevent bots from trying to brute-force their way in; after 20 failed attempts from a given IP, you need to wait half an hour to try logging in again.

This is just a proof of concept, I don't think you should keep the file structure like this, but you could.

Also, you could easily use memcached or riak or something more efficient to store session data.

Check this out: http://cylesoft.com/

php-secure-login's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.