Last active
August 29, 2015 14:22
-
-
Save nesvand/672c85cefda3787de75b to your computer and use it in GitHub Desktop.
"password protected" page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Base64 = { | |
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", | |
encode: function(a) { | |
var c, d, e, f, g, h, i, b = "", | |
j = 0; | |
for (a = Base64._utf8_encode(a); j < a.length;) c = a.charCodeAt(j++), d = a.charCodeAt(j++), e = a.charCodeAt(j++), f = c >> 2, g = (3 & c) << 4 | d >> 4, h = (15 & d) << 2 | e >> 6, i = 63 & e, isNaN(d) ? h = i = 64 : isNaN(e) && (i = 64), b = b + this._keyStr.charAt(f) + this._keyStr.charAt(g) + this._keyStr.charAt(h) + this._keyStr.charAt(i); | |
return b | |
}, | |
_utf8_encode: function(a) { | |
a = a.replace(/\r\n/g, "\n"); | |
for (var b = "", c = 0; c < a.length; c++) { | |
var d = a.charCodeAt(c); | |
128 > d ? b += String.fromCharCode(d) : d > 127 && 2048 > d ? (b += String.fromCharCode(192 | d >> 6), b += String.fromCharCode(128 | 63 & d)) : (b += String.fromCharCode(224 | d >> 12), b += String.fromCharCode(128 | 63 & d >> 6), b += String.fromCharCode(128 | 63 & d)) | |
} | |
return b | |
} | |
}; | |
$(document).ready(function() { | |
var $tabpanel = $('#tabpanel'); | |
var $portalPassword = $('#portal-password'); | |
$tabpanel.css({ | |
'display': 'none' | |
}); | |
// Clears any fields in the form when the user clicks on them | |
$('#passwordInput:input, #passwordInput select').focus(function() { | |
if ($(this).hasClass("requiredval")) { | |
$(this).val("").removeClass("requiredval"); | |
} | |
}); | |
$portalPassword.on('submit', function(e) { | |
var target = 'bGl0dGxlNDYyNg=='; //little4626 | |
var password = this[0].value; | |
e.preventDefault(); | |
if (password) { | |
var encoded = Base64.encode(password); | |
if (target == encoded) { | |
$tabpanel.css({ | |
'display': 'block' | |
}); | |
$portalPassword.css({ | |
'display': 'none' | |
}); | |
} else { | |
$(this[0]).addClass('requiredval'); | |
$(this[0]).val(''); | |
$(this[0]).attr('placeholder', 'Please try again'); | |
} | |
} else { | |
$(this[0]).addClass('requiredval'); | |
$(this[0]).attr('placeholder', 'Please enter a password'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment