Git Product home page Git Product logo

hashtoken's Introduction

HashToken is a PHP class for generating expiring tokens. The class does not
rely on the database, rather it uses simple mathematics and the current time on
the local server to work out whether a token has expired or not.

The class uses SHA256 hashing along with a secret key to keep things secure. You
should change the KEY constant before using the code.

The tokens are plaintext, and can be passed to the user for example when a form
page is generated. When the form is posted, the server may check if the token is
still valid, ensuring the form was submitted in the allotted timeframe.

This is useful for preventing web scrapers from crawling forms that are not
prudent to attach a CAPCHA to, such as an advanced search form. A token can be
created to emerge in 5 seconds and expire in 24 hours.

This all happens without any storage of tokens on the server side whatsoever.
Multiple servers can also validate eachothers keys if they share the secret key.

The class has two functions, GetToken and CheckToken:

GetToken takes 2 or 3 parameters, UserKey, ExpireTime, and EmergeTime.
GetToken returns a string representing the token.

	UserKey
		- Secret key for this particular token.
		- Necessary to determine token validity.
		- May be NULL (must then also be NULL on CheckToken)

	ExpireTime
		- Validity time of token in seconds
		- If Emerge Time is set, this begins AFTER emerge time

	EmergeTime - Time in seconds to wait before considering token valid

CheckToken takes 2 parameters, Token and UserKey
CheckToken returns a boolean indicating whether or not the token is currently valid.

	Token
		-The token string generated by GetToken

	UserKey
		-The UserKey passed into GetToken. May Be NULL.

hashtoken's People

Watchers

Sean Morris avatar  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.