(len)
| 1 | var crypto = require('crypto'); |
| 2 | |
| 3 | function uid(len) { |
| 4 | return crypto.randomBytes(Math.ceil(len * 3 / 4)) |
| 5 | .toString('base64') |
| 6 | .slice(0, len) |
| 7 | .replace(/\//g, '-') |
| 8 | .replace(/\+/g, '_'); |
| 9 | } |
| 10 | |
| 11 | // The xsrf middleware provide AngularJS style XSRF-TOKEN provision and validation |
| 12 | // Add it to your server configuration after the session middleware: |