Assignment 10

by sheila massey

HTML

<h1>Password Hashing</h1>

<input type='text' id='value' value=''  size='34'>

<br>
<br>

<input type='button' value='Check Password' onclick='checkForPassword();'>
<input type='button' value='Add Password' onclick='pushNode();'>
<input type='button' value='Remove Password' onclick='popNode();'>
<div id='outp'>

</div>
<div id='outp2'>

</div>

JavaScript

///////////////////////////////////////////////////////////////////////////////////////////
var Node = function(_c) 
{
  this.next = null;
  this.prev = null;
  this.key = SHA256(_c);
  return this;
}
//////////////////////////////////////////////////////////////////////////////////////////
var List = function(_c) 
{
  this.head = null;
  this.tail = null;
  this.length = 0;
  return this;
}
///////////////////////////////////////////////////////////////////////////////////////////////
List.prototype.listToString = function() 
{
  var str = '';
  var cnode = this.head;
  while (cnode != null) 
    {
      str += cnode.key + '<br>';
      cnode = cnode.next;
    }
  return str;
}
//////////////////////////////////////////////////////////////////////////////////////////////
List.prototype.push = function(_c) 
{
  var node = new Node(_c);
  node.c = _c;
  if (this.head == null) 
  {
    this.head = node;
    this.tail = node;
    this.length++;
    return node;
  }

  node.prev = this.tail;
  this.tail.next = node;
  this.tail = node;
  this.length++;
  return node;
}
/////////////////////////////////////////////////////////////////////////////////////////
List.prototype.pop = function() 
{
  var poppedNode = this.tail;
  if (this.head == null) 
  {
    alert('List is empty, cannot pop');
    return null;
  }
  if (this.head == this.tail) 
  {
    this.head = null;
    this.tail = null;
    this.length--;
    return poppedNode;
  }
  this.tail = this.tail.prev;
  this.tail.next = null;
  this.length--;
  return poppedNode;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
var L = new List();
var passwords = new List();
///////////////////////////////////////////////////////////////////////////////////////////////
function pushNode(value)
{
  value = document.getElementById('value').value;
  L.push(value);
  document.getElementById('outp').innerHTML =...