Last active
December 23, 2015 00:09
-
-
Save lankanmon/6552231 to your computer and use it in GitHub Desktop.
Code snippets for Post on TGHD - http://theglobalhelpdesk.com/v/900353363/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 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