1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/firefoxos/main.js Mon Apr 22 22:00:43 2013 +0200 1.3 @@ -0,0 +1,79 @@ 1.4 +/* 1.5 + * OTPWCalc - One time password challenge response calculator client 1.6 + * Copyright © 2013 Michael Schloh von Bennewitz <michael@schloh.com> 1.7 + * 1.8 + * OTPWCalc is free software: you can redistribute it and/or modify 1.9 + * it under the terms of the European Union Public Licence, either 1.10 + * version 1.1 of the license, or (at your option) any later version. 1.11 + * 1.12 + * OTPWCalc is distributed in the hope that it will be useful, 1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty 1.14 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 1.15 + * the European Union Public License for more details. 1.16 + * 1.17 + * You should have received a copy of the European Union Public 1.18 + * Licence along with OTPWCalc. If not, please refer to 1.19 + * <http://joinup.ec.europa.eu/software/page/eupl/>. 1.20 + * 1.21 + * This file is part of project OTWPCalc, a one time password challenge 1.22 + * response calculator client and is found at http://otpwcalc.europalab.com/ 1.23 + * 1.24 + * main.js: ECMA JavaScript implementation 1.25 + */ 1.26 + 1.27 +// <![CDATA[ 1.28 +//// This doesn't work with AJAX (use pageinit instead) 1.29 +//// That means JavaScript in the head of any other HTML 1.30 +//// will be ignored, only the data-role="page" is parsed 1.31 +//$(document).ready(function() { 1.32 + //$.mobile.ajaxLinksEnabled = false; 1.33 +//}); 1.34 +$(document).on("mobileinit", function() { 1.35 + $.extend( $.mobile , { 1.36 + pageLoadErrorMessage: 'Either the page cannot be found or it cannot be loaded.' 1.37 + }); 1.38 +}); 1.39 +//$(document).on("pageinit", function() { 1.40 +//}); 1.41 + 1.42 +// the main logical entry point 1.43 +function otpwcalc() { 1.44 + var secr = $('#paswrd').val(); 1.45 + var user = $('#seedid').val(); 1.46 + var iter = parseInt($('#crement').val(), 10); 1.47 + var hash = genotpmd5; 1.48 + if ($('form input[name=radiohash]:checked').attr('id') == 'hashsha1') 1.49 + hash = genotpsha1; 1.50 + else if ($('form input[name=radiohash]:checked').attr('id') == 'hashr160') 1.51 + hash = genotprmd160; 1.52 + var form = arrtosix; 1.53 + if ($('form input[name=radiodisplay]:checked').attr('id') == 'displayhex') 1.54 + form = arrtohex; 1.55 + var resp = hash(secr, user, iter); 1.56 + //var resp = sjcl.random.randomWords(1,0); 1.57 + return form(resp); 1.58 +} 1.59 + 1.60 +// helper function 1.61 +function dosubmit() { 1.62 + if ($('#seedid').val().length == 0) { 1.63 + $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Seed ID'); 1.64 + return false; 1.65 + } 1.66 + else if ($('#crement').val().length == 0 || isNaN($('#crement').val())) { 1.67 + $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Sequence #'); 1.68 + return false; 1.69 + } 1.70 + else { 1.71 + $('#outext').css({'font-size': '0.9em', 'padding-top': '0.25em'}).text(otpwcalc()); 1.72 + $('#crement').val(parseInt($("#crement").val()) - $('#selectdecr').val()); 1.73 + return false; 1.74 + } 1.75 +} 1.76 + 1.77 +// helper function 1.78 +function doreset() { 1.79 + $('#outext').css({'font-size': '1.125em', 'padding-top': '0'}).text('Please Click Submit For A OTP'); 1.80 + return true; 1.81 +} 1.82 +// ]]>