THIS IS NOT A PASSWORD HASH. You don't want to use SHA256 (or even 512 for that matter) to hash passwords. It's too fast, which makes it (relatively) easy to brute force small amounts of hashed data. It's much better for generating tokens, sessions, cookies, or encrypting larger data sets. We only use it in a few places in UserSpice, but it's available to you if you need it for something. If you want to do some password-type encryption, use bcrpyt or something similar.


Super simple…

$hash = Hash::unique();

Notice that it is a static method and it needs the ::


If you copy and paste this code, please get rid of the space before the opening php tag.

class Hash{
	public static function make($string, $salt = ''){
		return hash('sha256', $string . $salt);

	public static function salt($length){
		return mcrypt_create_iv($length);

	public static function unique(){
		return self::make(uniqid());