* Generates a random string of hex characters that is len characters long. * It will have the security of a len/2 password * * @param {Number} len The length of the API key to generate. * @return {String} A string representing len # of random bytes.
(len)
| 38 | * @return {String} A string representing len # of random bytes. |
| 39 | */ |
| 40 | function createAPIKey(len) { |
| 41 | return crypto.randomBytes(Math.ceil(len / 2)) |
| 42 | .toString('hex') // convert to hexadecimal format |
| 43 | .slice(0, len); // return required number of characters |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Validates the user identified in the request session is an admin. |