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 | |
// Generates a strong password of N length containing at least one lower case letter, | |
// one uppercase letter, one digit, and one special character. The remaining characters | |
// in the password are chosen at random from those four sets. | |
// | |
// The available characters in each set are user friendly - there are no ambiguous | |
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option, | |
// makes it much easier for users to manually type or speak their passwords. | |
// | |
// Note: the $add_dashes option will increase the length of the password by |
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 | |
// usage: $newpassword = generatePassword(12); // for a 12-char password, upper/lower/numbers. | |
// functions that use rand() or mt_rand() are not secure according to the PHP manual. | |
function getRandomBytes($nbBytes = 32) | |
{ | |
$bytes = openssl_random_pseudo_bytes($nbBytes, $strong); | |
if (false !== $bytes && true === $strong) { | |
return $bytes; | |
} |
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
function onlyStatic (middleware) { | |
return function (req, res, next) { | |
var match = /(\.css|\.eot|\.gif|\.html|\.js|\.png|\.svg|\.ttf|\.woff)($|\?.*$)/ig.exec(req.originalUrl); | |
if (!match) return next(); | |
middleware(req, res, next); | |
}; | |
} | |
//usage | |
this.use(onlyStatic(express.static(__dirname + "/public"))); |