Password Hashing
by hesster92
HTML
<label for="data">Add Password To List:</label>
<input type ="textbox" id="data" placeholder="Text Input" />
<input type="button" value="Submit" onclick="addPassword()" />
<label for="hashCheck">Check For Password:</label>
<input type="textbox" id="hashCheck" placeholder="Text Input" />
<input type="button" value="Submit" onclick="checkHash()" />
JavaScript
function LinkedList() {
this.head = null;
this.tail = null;
this.length = 0;
}
function Node() {
this.next = null;
this.prev = null;
this.content = null;
}
LinkedList.prototype.add = function(_content) {
var node = new Node();
node.content = _content;
if (this.head == null) {
this.head = node;
this.length = 1;
return node.content;
}
if (this.tail == null) {
this.tail = node;
this.tail.prev = this.head;
this.head.next = this.tail;
this.length++;
return node.content;
}
this.tail.next = node;
node.prev = this.tail;
this.tail = node;
this.length++;
return node.content;
}
function hashCode(str){
var hash = 0, len = str.length;
if (len === 0) {
return hash;
}
for (i = 0; i < len; i++) {
charC = str.charCodeAt(i);
hash = ((hash << 5 ) - hash) + charC;
hash = hash & hash; // Convert to 32bit integer
}
console.log(hash);
return hash;
}
var password = new LinkedList();
function addPassword() {
var i = document.getElementById("data").value;
var hash = hashCode(i);
password.add(hash);
}
function checkHash(){
var j = document.getElementById("hashCheck").value;
var checkHash = hashCode(j);
password.hashCheck(checkHash);
}
LinkedList.prototype.hashCheck = function(_content){
var i = this.head;
var verified = _content;
for(i = this.head; i != null; i = i.next){
if(i.content != verified){
console.log("Not Found");
document.getElementById("hashCheck").value = ("Not Found");
}
else{
console.log("Password Found");
document.getElementById("hashCheck").value = "Password Found";
}
}
}
/*
Assignment 10 – Password Hashing
Summary
Password hashing is commonly used in nearly all systems. The concept is simple – it is not secure to store raw password in a system, but we still need to provide password based authentication. This will show you how it is done.
Assignment
The first step of this...