src/firefoxos/main.js

Mon, 22 Apr 2013 22:00:43 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 22 Apr 2013 22:00:43 +0200
changeset 0
6a0957738c54
child 4
5d1908d87db8
permissions
-rw-r--r--

Import pristine sources of new project OTPWCalc.

michael@0 1 /*
michael@0 2 * OTPWCalc - One time password challenge response calculator client
michael@0 3 * Copyright © 2013 Michael Schloh von Bennewitz <michael@schloh.com>
michael@0 4 *
michael@0 5 * OTPWCalc is free software: you can redistribute it and/or modify
michael@0 6 * it under the terms of the European Union Public Licence, either
michael@0 7 * version 1.1 of the license, or (at your option) any later version.
michael@0 8 *
michael@0 9 * OTPWCalc is distributed in the hope that it will be useful,
michael@0 10 * but WITHOUT ANY WARRANTY; without even the implied warranty
michael@0 11 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
michael@0 12 * the European Union Public License for more details.
michael@0 13 *
michael@0 14 * You should have received a copy of the European Union Public
michael@0 15 * Licence along with OTPWCalc. If not, please refer to
michael@0 16 * <http://joinup.ec.europa.eu/software/page/eupl/>.
michael@0 17 *
michael@0 18 * This file is part of project OTWPCalc, a one time password challenge
michael@0 19 * response calculator client and is found at http://otpwcalc.europalab.com/
michael@0 20 *
michael@0 21 * main.js: ECMA JavaScript implementation
michael@0 22 */
michael@0 23
michael@0 24 // <![CDATA[
michael@0 25 //// This doesn't work with AJAX (use pageinit instead)
michael@0 26 //// That means JavaScript in the head of any other HTML
michael@0 27 //// will be ignored, only the data-role="page" is parsed
michael@0 28 //$(document).ready(function() {
michael@0 29 //$.mobile.ajaxLinksEnabled = false;
michael@0 30 //});
michael@0 31 $(document).on("mobileinit", function() {
michael@0 32 $.extend( $.mobile , {
michael@0 33 pageLoadErrorMessage: 'Either the page cannot be found or it cannot be loaded.'
michael@0 34 });
michael@0 35 });
michael@0 36 //$(document).on("pageinit", function() {
michael@0 37 //});
michael@0 38
michael@0 39 // the main logical entry point
michael@0 40 function otpwcalc() {
michael@0 41 var secr = $('#paswrd').val();
michael@0 42 var user = $('#seedid').val();
michael@0 43 var iter = parseInt($('#crement').val(), 10);
michael@0 44 var hash = genotpmd5;
michael@0 45 if ($('form input[name=radiohash]:checked').attr('id') == 'hashsha1')
michael@0 46 hash = genotpsha1;
michael@0 47 else if ($('form input[name=radiohash]:checked').attr('id') == 'hashr160')
michael@0 48 hash = genotprmd160;
michael@0 49 var form = arrtosix;
michael@0 50 if ($('form input[name=radiodisplay]:checked').attr('id') == 'displayhex')
michael@0 51 form = arrtohex;
michael@0 52 var resp = hash(secr, user, iter);
michael@0 53 //var resp = sjcl.random.randomWords(1,0);
michael@0 54 return form(resp);
michael@0 55 }
michael@0 56
michael@0 57 // helper function
michael@0 58 function dosubmit() {
michael@0 59 if ($('#seedid').val().length == 0) {
michael@0 60 $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Seed ID');
michael@0 61 return false;
michael@0 62 }
michael@0 63 else if ($('#crement').val().length == 0 || isNaN($('#crement').val())) {
michael@0 64 $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Sequence #');
michael@0 65 return false;
michael@0 66 }
michael@0 67 else {
michael@0 68 $('#outext').css({'font-size': '0.9em', 'padding-top': '0.25em'}).text(otpwcalc());
michael@0 69 $('#crement').val(parseInt($("#crement").val()) - $('#selectdecr').val());
michael@0 70 return false;
michael@0 71 }
michael@0 72 }
michael@0 73
michael@0 74 // helper function
michael@0 75 function doreset() {
michael@0 76 $('#outext').css({'font-size': '1.125em', 'padding-top': '0'}).text('Please Click Submit For A OTP');
michael@0 77 return true;
michael@0 78 }
michael@0 79 // ]]>

mercurial