//
// crAuth: A challenge reponse authentication extension for the integrated autentication system of the cakePHP framework.
// Copyright (c)	2009, Dirk Küppers
// Licensed under The MIT License
// Redistributions of files must retain the above copyright notice.
//
// @author			Dirk Küppers
// @copyright		Copyright (c) 2009, Dirk Küppers
// @version			0.1
// @modifiedby		DK
// @lastmodified	$Date: 2006-12-04 16:18:00 +0000 (Mon, 4 Dec 2006) $
// @license			http://www.opensource.org/licenses/mit-license.php The MIT License
//

//
// hash password with username and challenge
//
function doHash()
{
	var username = document.getElementById('UserUsername').value;
	var password = document.getElementById('UserPassword').value;
	var challenge = document.getElementById('UserChallenge').value;
	document.getElementById('UserPassword').value = randomString(password.length);
	document.getElementById('UserResponse').value = MD5(username + ":" + MD5(password) + ":" + challenge);
//	document.getElementById('UserChallenge').value = '';
	return true;
}

function randomString(len)
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var randomstring = '';
	for (var i=0; i<len; i++)
	{
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}
