Here is the JavaScript code that captures the keystroke dynamics of a demo user and how to make WebDNA analyze it
numero = 1027<html> <head> <title>Keystroke capture demo</title> <script> function KeystrokeDynamicsCapture ( targetControlId ) { vk_arr = []; ht_arr = []; ft_arr = []; pendingKeyDown = {}; lastKeyDown = undefined; this.clear = function () { vk_arr = []; ht_arr = []; ft_arr = []; pendingKeyDown = {}; lastKeyDown = undefined; } var BACKSPACE = 8; this.serializeKeystrokeData = function () { final_size = 0;final = []; var retval = ''; for ( i = 0 ; i < ht_arr.length ; i++ ) if ( vk_arr[i] == BACKSPACE ) { if ( final_size != 0 ) final_size--; } else { final[final_size] = i; final_size++; } for ( i = 0 ; i < final_size ; i++ ) { var pos = final[i]; retval += vk_arr[pos] + ':' + ht_arr[pos] + '/' + ft_arr[pos] + '-'; }return retval; } function printDebug(str) { var dbg = document.getElementById("debug"); dbg.innerHTML = str + "<br />" + dbg.innerHTML; } function formatLists() { var retval = '['; for ( i = 0 ; i < ht_arr.length ; i++ ) retval += '(' + vk_arr[i] + '/' + ht_arr[i] + '-' + ft_arr[i] + ')'; return retval + ']'; } var last_key_is_backspace = false; function onKeyDown(e) {var d = new Date(); vk_arr.push(e.keyCode); if ( lastKeyDown == undefined || last_key_is_backspace ) ft_arr.push(0); else { var ft = d.getTime() - lastKeyDown; ft_arr.push(ft); printDebug('KEY ' + e.keyCode + ' FT ' + ft + ' ' + formatLists()); } lastKeyDown = d.getTime(); if ( pendingKeyDown[e.keyCode] == undefined ) pendingKeyDown[e.keyCode] = d.getTime(); last_key_is_backspace = e.keyCode == BACKSPACE; } function onKeyUp(e) { var d = new Date(); if ( pendingKeyDown[e.keyCode] != undefined ) { var ht = d.getTime() - pendingKeyDown[e.keyCode]; ht_arr.push(ht); pendingKeyDown[e.keyCode] = undefined; printDebug('KEY ' + e.keyCode + ' HT ' + ht + ' ' + formatLists()); } } function registerHandlers(targetControlId) { var ctrl = document.getElementById(targetControlId); ctrl.addEventListener("keydown", onKeyDown); ctrl.addEventListener("keyup", onKeyUp); } registerHandlers(targetControlId); } var ksdc; function registerHandlers(targetControlId) { ksdc = new KeystrokeDynamicsCapture(targetControlId); } function getKeystrokeDynamicsData() { // alert(ksdc.serializeKeystrokeData()); document.getElementById("result").innerHTML += ksdc.serializeKeystrokeData() + "|"; ksdc.clear(); } function sendKeystrokeDynamicsData() { form = document.getElementById('myTestForm'); // Delete old form data if it exists oldelem = document.getElementById('captureid'); if (oldelem) form.removeChild(oldelem); myvar = document.createElement('input'); myvar.setAttribute('name', 'capture'); myvar.setAttribute('type', 'hidden'); myvar.setAttribute('id', 'captureid'); myvar.setAttribute('value', ksdc.serializeKeystrokeData()); form.appendChild(myvar); form.submit(); } </script> </head> <body onload="registerHandlers('targetControl');"> <form action="ksdtest.dna" method=POST id='myTestForm'> <input type="text" name="targetControl" id="targetControl" value="" size="64" maxlength="128" /> <br /> METHOD:<br /> <input type="radio" name="method" value="initialize">Initialize<br /> <input type="radio" name="method" value="train">Train<br /> <input type="radio" name="method" value="evaluate" checked="checked">Evaluate<br /> BTTHRESHOLD: <input type="text" name="btthreshold" value="0.69" size=3><br /> BTCORRECTIONS: <input type="text" name="btcorrections" value="1" size=3><br /> BTLENGTH: <input type="text" name="btlength" value="8" size=3><br /> BTUSER: <input type="text" name="btuser" value="demouser" size=8><br /> BTTYPE: <input type="radio" name="bttype" value="password">Password <input type="radio" name="bttype" value="TEXT" checked="checked">Text<br /> <input type="button" onclick="sendKeystrokeDynamicsData();" value="Submit data"> </form> <br /> <hr /> <div id="debug" /> </body></html>
You will see a simple form, with a field, radio buttons to show the three methods and parameteres described here.Start by typing an 8 characters password, using method "Initialize": this will open and store the user profile in a database in your WebDNA folder. At the same time, you will dynamically visualize the keystroke dynamics capture. Submit, then type and submit the same password two or three more time, in a consistent way, using the "Train" method. You are now ready to test. The treshold has been set at 0.69: depending on this value, the next page will show "LEGITIMATE" or "IMPOSTOR"
As you can see, we named the next page "ksdtest.dna":<!--HAS_WEBDNA_TAGS--><center><font size="20" color="[showif [BIOTYPE]=LEGITIMATE]green[/showif][showif [BIOTYPE]=IMPOSTOR]red[/showif]">[BIOTYPE]</font><br />deviation : [DEMOUSER_deviation]<META HTTP-EQUIV="Refresh" CONTENT="3;URL=KSD.html">ADGS is currently refining the method but it is already one of the most accurate method ever implemented in matter of keystroke dynamics. You will need one html form, that we named "KSD.html", containing all the JavaScript code, and one very simple return page.
<html>
<head>
<title>Keystroke capture demo</title>
<script>
function KeystrokeDynamicsCapture ( targetControlId )
{
vk_arr = [];
ht_arr = [];
ft_arr = [];
pendingKeyDown = {};
lastKeyDown = undefined;
this.clear = function ()
{
vk_arr = [];
ht_arr = [];
ft_arr = [];
pendingKeyDown = {};
lastKeyDown = undefined;
}
var BACKSPACE = 8;
this.serializeKeystrokeData = function ()
{
final_size = 0;
final = [];
var retval = '';
for ( i = 0 ; i < ht_arr.length ; i++ )
if ( vk_arr[i] == BACKSPACE )
{
if ( final_size != 0 )
final_size--;
}
else
{
final[final_size] = i;
final_size++;
}
for ( i = 0 ; i < final_size ; i++ )
{
var pos = final[i];
retval += vk_arr[pos] + ':' + ht_arr[pos] + '/' + ft_arr[pos] + '-';
}
return retval;
}
function printDebug(str)
{
var dbg = document.getElementById("debug");
dbg.innerHTML = str + "<br />" + dbg.innerHTML;
}
function formatLists()
{
var retval = '[';
for ( i = 0 ; i < ht_arr.length ; i++ )
retval += '(' + vk_arr[i] + '/' + ht_arr[i] + '-' + ft_arr[i] + ')';
return retval + ']';
}
var last_key_is_backspace = false;
function onKeyDown(e)
{
var d = new Date();
vk_arr.push(e.keyCode);
if ( lastKeyDown == undefined || last_key_is_backspace )
ft_arr.push(0);
else
{
var ft = d.getTime() - lastKeyDown;
ft_arr.push(ft);
printDebug('KEY ' + e.keyCode + ' FT ' + ft + ' ' + formatLists());
}
lastKeyDown = d.getTime();
if ( pendingKeyDown[e.keyCode] == undefined )
pendingKeyDown[e.keyCode] = d.getTime();
last_key_is_backspace = e.keyCode == BACKSPACE;
}
function onKeyUp(e)
{
var d = new Date();
if ( pendingKeyDown[e.keyCode] != undefined )
{
var ht = d.getTime() - pendingKeyDown[e.keyCode];
ht_arr.push(ht);
pendingKeyDown[e.keyCode] = undefined;
printDebug('KEY ' + e.keyCode + ' HT ' + ht + ' ' + formatLists());
}
}
function registerHandlers(targetControlId)
{
var ctrl = document.getElementById(targetControlId);
ctrl.addEventListener("keydown", onKeyDown);
ctrl.addEventListener("keyup", onKeyUp);
}
registerHandlers(targetControlId);
}
var ksdc;
function registerHandlers(targetControlId)
{
ksdc = new KeystrokeDynamicsCapture(targetControlId);
}
function getKeystrokeDynamicsData()
{
// alert(ksdc.serializeKeystrokeData());
document.getElementById("result").innerHTML += ksdc.serializeKeystrokeData() + "|";
ksdc.clear();
}
function sendKeystrokeDynamicsData()
{
form = document.getElementById('myTestForm');
// Delete old form data if it exists
oldelem = document.getElementById('captureid');
if (oldelem) form.removeChild(oldelem);
myvar = document.createElement('input');
myvar.setAttribute('name', 'capture');
myvar.setAttribute('type', 'hidden');
myvar.setAttribute('id', 'captureid');
myvar.setAttribute('value', ksdc.serializeKeystrokeData());
form.appendChild(myvar);
form.submit();
}
</script>
</head>
<body onload="registerHandlers('targetControl');">
<form action="ksdtest.dna" method=POST id='myTestForm'>
<input type="text" name="targetControl" id="targetControl" value="" size="64" maxlength="128" />
<br />
METHOD:<br />
<input type="radio" name="method" value="initialize">Initialize<br />
<input type="radio" name="method" value="train">Train<br />
<input type="radio" name="method" value="evaluate" checked="checked">Evaluate<br />
BTTHRESHOLD: <input type="text" name="btthreshold" value="0.69" size=3><br />
BTCORRECTIONS: <input type="text" name="btcorrections" value="1" size=3><br />
BTLENGTH: <input type="text" name="btlength" value="8" size=3><br />
BTUSER: <input type="text" name="btuser" value="demouser" size=8><br />
BTTYPE: <input type="radio" name="bttype" value="password">Password <input type="radio" name="bttype" value="TEXT" checked="checked">Text<br />
<input type="button" onclick="sendKeystrokeDynamicsData();" value="Submit data">
</form>
<br />
<hr />
<div id="debug" />
</body>
</html>
You will see a simple form, with a field, radio buttons to show the three methods and parameteres described here.
Start by typing an 8 characters password, using method "Initialize": this will open and store the user profile in a database in your WebDNA folder. At the same time, you will dynamically visualize the keystroke dynamics capture. Submit, then type and submit the same password two or three more time, in a consistent way, using the "Train" method. You are now ready to test. The treshold has been set at 0.69: depending on this value, the next page will show "LEGITIMATE" or "IMPOSTOR"
<!--HAS_WEBDNA_TAGS-->
<center>
<font size="20" color="[showif [biotype]=LEGITIMATE]green[/showif][showif [biotype]=IMPOSTOR]red[/showif]">[biotype]</font>
<br />
deviation : [DEMOUSER_deviation]
<META HTTP-EQUIV="Refresh" CONTENT="3;URL=KSD.html">
DOWNLOAD WEBDNA NOW!
WebDNA applications...
Tips and TricksA list of user-submitted tips ...
WebDNA ModulesA list of the currently available modules...
WebDNA LibrariesA list of available libraries for WebDNA...
[biotype]BioType is a behavioral biometrics WebDNA function based on ADGS research and development (from version 8...
Technical Change HistoryThis Technical Change History provides a reverse chronological list of WebDNA changes...
...
[addfields][addfields db=...
[removelineitem]...
[cookie]Cookies are a great way to remember visitors...
[thisurl][thisurl] displays the URL of the current page...
[createfolder]Create an empty folder on your webspace...