Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Created February 19, 2014 08:13
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 Noitidart/9087938 to your computer and use it in GitHub Desktop.
Save Noitidart/9087938 to your computer and use it in GitHub Desktop.
OAuth nonce generator function from codebird, its bascially a random string generator.
//https://github.com/jublonet/codebird-js/blob/master/codebird.js#L745
function _nonce(length) {
if (typeof length === "undefined") {
length = 8;
}
if (length < 1) {
console.warn("Invalid nonce length.");
}
var nonce = "";
for (var i = 0; i < length; i++) {
var character = Math.floor(Math.random() * 61);
nonce += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".substring(character, character + 1);
}
return nonce;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment