Skip to content

Instantly share code, notes, and snippets.

@maftieu
Forked from flesler/generate-pass.html
Created July 28, 2015 14:42
Show Gist options
  • Save maftieu/42e7eaf96799aa7f92c2 to your computer and use it in GitHub Desktop.
Save maftieu/42e7eaf96799aa7f92c2 to your computer and use it in GitHub Desktop.
Bookmarklet to generate deterministic passwords based on a service name
<pre>
(function(length, prefix, suffix, map) {
/* Version 1.0 */
var p = location.hostname.split('.');
// Find service name
do { var pass = p.pop(); }
while (p.length && pass.length <= 3);
// First time assume domain
if (!this._custom_) {
this._custom_ = true;
} else {
// If clicked again let them fill the name themselves
pass = prompt('Write the service name', pass);
}
// Replace characters, only once per character
for (var c in map) {
pass = pass.replace(new RegExp(c, 'i'), map[c]);
}
// Upper case first lower case char
pass = pass.replace(/[a-z]/, function(c) { return c.toUpperCase(); });
// Add prefix
pass = prefix + pass;
// Fill with suffix chars up to desired length
while (pass.length < length) {
var diff = length - pass.length;
pass += suffix.slice(-diff);
}
// Crop to desired length if larger
pass = pass.slice(0, length);
alert('Password:' + pass);
// NOTE: Change this values to customize your pass
})(10, 'Gp', '_T8e.P2j!', {
i: '!',
a: '@',
s: '$',
l: 1,
z: 2,
e: 3,
g: 6,
t: 7,
b: 8,
o: 0
});
</pre>
<br />
<!-- Minified and ready to be -->
<a href="javascript:(function(b,f,g,c){/*1.0*/var d=location.hostname.split('.');do var a=d.pop();while(d.length&&3>=a.length);this._C_?a=prompt('Write the service name',a):this._C_=!0;for(var e in c)a=a.replace(new RegExp(e,'i'),c[e]);a=a.replace(/[a-z]/,function(a){return a.toUpperCase()});for(a=f+a;a.length<b;)a+=g.slice(-(b-a.length));a=a.slice(0,b);alert('Password:'+a)})(10,'Gp','_T8e.P2j!',{i:'!',a:'@',s:'$',l:1,z:2,e:3,g:6,t:7,b:8,o:0});">
Generate Pass
</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment