-
Notifications
You must be signed in to change notification settings - Fork 131
/
pwdhash.js
46 lines (42 loc) · 1.44 KB
/
pwdhash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Remote PwdHash
* A JavaScript implementation of the PwdHash hashing algorithm.
* Version 1.0 Copyright (C) Stanford University 2004-2006
* Author: Collin Jackson
* Other Contributors: Dan Boneh, John Mitchell, Nick Miyake, and Blake Ross
* Distributed under the BSD License
* See http://crypto.stanford.edu/PwdHash for more info.
* Requires the Javascript MD5 library, available here: http://pajhome.org.uk/crypt/md5
*/
/*
* Initialize page with default hashing parameters.
*/
function Init() {
document.hashform.domain.value = "http://www.example.com/";
document.hashform.sitePassword.value = "";
document.hashform.hashedPassword.value = "Press Generate";
document.hashform.hashedPassword.disabled = true;
}
var SPH_kPasswordPrefix = "@@";
/*
* Returns a conforming hashed password generated from the form's field values.
*/
function Generate()
{
var uri = document.hashform.domain.value;
var domain = (new SPH_DomainExtractor()).extractDomain(uri);
var size = SPH_kPasswordPrefix.length;
var data = document.hashform.sitePassword.value;
if (data.substring(0, size) == SPH_kPasswordPrefix)
data = data.substring(size);
var result = new String(new SPH_HashedPassword(data, domain));
return result;
}
/*
* Obtain a conforming hashed password and put it in the hashed password field
*/
function GenerateToTextField()
{
document.hashform.hashedPassword.value = Generate();
document.hashform.hashedPassword.disabled = false;
}