Assignment 10 - Password Hashing
by Mike Kerney
HTML
<input type='text' id='pass' value='Password'>
<input type='button' value='Enter Password to Hash' onclick='addPass()'>
<br/>
<input type='text' id='passToSearch' value='Password'>
<input type='button' value='Search for Password' onclick='searchPass()'>
<br/>
<div id='output'>
</div>
<div id='output2'>
</div>
JavaScript
var Node = function(_content) {
this.content = SHA256(_content);
this.next = null;
this.prev = null;
return this;
};
var aList = function(_content) {
this.tail = null;
this.head = null;
this.length = 0;
return this;
};
aList.prototype.push = function(_content) {
var newNode = new Node(_content);
newNode.content = SHA256(_content);
if (this.head == null) {
this.head = newNode;
this.tail = this.head;
this.length++;
return this;
}
if (this.head == this.tail) {
this.tail = newNode;
this.tail.next = this.head;
this.head.prev = this.tail;
this.length++;
return this;
}
this.tail.prev = newNode;
newNode.next = this.tail;
this.tail = newNode;
this.length++;
return this;
};
aList.prototype.pop = function() {
var node1 = this.tail;
if (this.head == this.tail) {
this.tail = null;
this.head = null;
this.length--;
return node1;
}
this.tail = this.tail.prev;
this.tail.next = null;
this.length--;
return node1;
};
aList.prototype.print = function() {
var string = "";
var node = this.head;
while (node != null) {
string += node.content;
node = node.next;
}
return string;
};
var list = new aList();
function searchPass(passToSearch) {
passToSearch = document.getElementById('passToSearch').value;
var keySearch = SHA256(passToSearch);
var nodeToCheck = list.head;
while (nodeToCheck != null) {
if (nodeToCheck.content == keySearch) {
document.getElementById('output2').innerHTML = "Password Found";
return;
}
nodeToCheck = nodeToCheck.next;
}
document.getElementById('output2').innerHTML = "Password not found.";
return;
}
function addPass(pass) {
pass = document.getElementById('pass').value;
list.push(pass);
document.getElementById('output').innerHTML = list.print();
}
function SHA256(s) {
var chrsz = 8;
var hexcase = 0;
function safe_add(x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw =...