Skip to content

Instantly share code, notes, and snippets.

@lankanmon
Last active December 23, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lankanmon/6552231 to your computer and use it in GitHub Desktop.
Save lankanmon/6552231 to your computer and use it in GitHub Desktop.
Code snippets for Post on TGHD - http://theglobalhelpdesk.com/v/900353363/
<?php
/* There are many ways to use crypt() in PHP, but I have found this to be useful and practical. */
//For generating Salt:
$salt = substr(str_shuffle("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345‌​6789"), 0, 8);
//or if you have a linux server, this is a much more random way of generating salt
$fp = fopen(''/dev/urandom'', ''r'');
$randomString = fread($fp, 32);
fclose($fp);
//Base 64 encode to ensure that some characters will not cause problems for crypt
$salt = base64_encode($randomString);
//For Hashing:
$hashed = crypt($passwordInput, ''$6$''.$salt);
//To Confirm:
if (crypt($passwordInput, $hashed) == $hashed) {
// Valid action
} else {
// Invalid action
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment