/*** DOCUMENTATION LAYER mushpup mirror library File: mushpup_mirror.js Last Update: Aug 2006 Author: Tom Atwell (klenwell@gmail.com) License: New BSD (details below) FUNCTIONS: cx_mushpup(autostyle) _mushpup_cx_form(autostyle) _mushpup_cx_hash(autostyle) _mushpup_cx_title(autostyle) mushpup_get_hash() mushpup_style_hash(raw_hash) mushpup_show_passkey_confirm(show) mushpup_reset_form() mushpup_reset_mirror() add_hash_ruler(the_hash) NOTES: This library is designed to ease the portability of mushpup. It depends on the following files: mushpup/lime_basic.js mushpup/mushpup_algorithm.js third_party/sha1.js Available at: http://mushpup.org/js_bin/ http://mushpup.googlecode.com/svn/trunk/ This code released under the terms of the new BSD license. To link: ______________________________________________________________________________*/ // cx_mushpup /*____________________________________________________________________________*/ function cx_mushpup_mirror(autostyle) { // *** DATA // Inline Styles var _style = ''; // Blocks var _div_form = ''; var _div_hash = ''; // Return var mushpup_html = ''; // *** MANIPULATE // Normalize Autostyle if ( autostyle == null || autostyle == 1 || autostyle == true ) { autostyle = 1; } else { autostyle = 0; } // Autoset Styles if ( autostyle ) { _style = 'width:auto; padding:10px; border:1px solid #ccc;'; } // Construct Title _div_title = _mushpup_cx_title(autostyle); // Construct Form _div_form = _mushpup_cx_form(autostyle); // Construct Hash _div_hash = _mushpup_cx_hash(autostyle); // Full Block mushpup_html += '
' + _div_title + _div_form + _div_hash + '
'; // Print Now js_echo(mushpup_html); // *** RETURN return; } // end Fx /*____________________________________________________________________________*/ // mushpup_cx_form /*____________________________________________________________________________*/ function _mushpup_cx_form( autostyle ) { // *** DATA // Inline Style var _mfp_inline = ''; var _mf_inline = ''; var _label_inline = ''; // Return this_html = ''; // *** MANIPULATE // Autoset Styles if ( autostyle ) { _mfp_inline = 'font-family:arial,sans-serif; font-size:14px; color:#333; padding-top:10px;'; _mf_inline = ''; _label_inline = 'display:block; float:left; width:150px; padding-right:4px; font-weight:bold; font-size:13px;'; } // Open Block this_html += '
'; // Open Form this_html += '
'; // Site Field this_html += '

'; // Site Advice // this_html += '

for websites, it`s simpler to use only the basic domain name (e.g. yahoo.com rather than http://www.yahoo.com/login/). but however you choose to do it, just make sure you`re consistent.

'; // MSW Field this_html += '

'; // Confirm Toggle this_html += '

click here to add confirm field(recommended if you are registering a password for first time at a site)

'; // Confirm Field this_html += ''; // Buttons this_html += '

'; // Close Form this_html += '
'; // Close Stack this_html += '
'; // *** RETURN return this_html; } // end Fx /*____________________________________________________________________________*/ // mushpup_cx_hash /*____________________________________________________________________________*/ function _mushpup_cx_hash( autostyle ) { // *** DATA // Year var jsYear = new Date().getFullYear(); // Inline Style var _stack_inline = 'width:auto;'; var _block_inline = ''; // Return this_html = ''; // *** MANIPULATE // Autoset Styles if ( autostyle ) { _stack_inline = ' margin:0 auto; padding-left:20px;'; _block_inline = 'border:0px solid #eee; padding:4px;'; } // Hash Block this_html += ''; // *** RETURN return this_html; } // end Fx /*____________________________________________________________________________*/ // mushpup_cx_hash /*____________________________________________________________________________*/ function _mushpup_cx_title( autostyle ) { // *** DATA // Inline Style var _div_inline = ''; var _h2_inline = ''; var _info_inline = ''; // Return this_html = ''; // *** MANIPULATE // Autoset Styles if ( autostyle ) { _div_inline = ''; _h2_inline = 'margin:0; color:#ccc; font-family:Trebuchet MS,helvetica,sans-serif; font-size:32px; font-weight:normal;'; _info_inline = 'margin:0 0 12px; font-family:verdana,helvetica,sans-serif; font-size:11px; color:#ccc;'; } // Title and Link this_html += '
'; this_html += '

mushpup

'; this_html += '

more info at mushpup.org

'; this_html += '
'; // *** RETURN return this_html; } // end Fx /*____________________________________________________________________________*/ // mushpup_get_hash() /*____________________________________________________________________________*/ function mushpup_get_hash() { // *** DATA // Debug var _debug = 0; // Document Objects var dom_key = document.getElementsByName("mushpup_passkey")[0]; var dom_check_key = document.getElementsByName("passkey_confirm_input")[0]; var dom_context = document.getElementsByName("site")[0]; var dom_password = document.getElementsByName("password_hash")[0]; // Internal var input_key = ''; var input_context = ''; var trim_key = ''; var trim_context = ''; var salt = ''; var raw_hash = ''; var the_hash = ''; var _hash_html = ''; // Return // void // *** MANIPULATE // DEBUG if ( _debug ) alert('mushpup called'); // Get Values input_key = dom_key.value; input_check_key = dom_check_key.value; input_context = dom_context.value; // Trim Input Fields trim_key = js_trim(input_key); trim_check_key = js_trim(input_check_key); trim_context = js_trim(input_context); // DEBUG if ( _debug ) alert('input key: ' + input_key); if ( _debug ) alert('trim_check_key: ' + trim_check_key); // Check Keys if ( (trim_check_key != '__^skip$__') && (trim_key != trim_check_key) ) { alert("your mushpup secret words didn't match. carefully re-enter them."); return; } // Empty Warnings if ( trim_key == "" ) alert('Warning: the mushpup secret word you entered is blank.'); if ( trim_context == "" ) alert('Warning: the url you entered is blank.'); // Concatenate salt = trim_context + trim_key; if ( _debug ) alert('salt: ' + salt); // Prepare Hash // Computer Hash raw_hash = mushpup_sha24(salt); // Style Hash styled_hash = mushpup_style_hash(raw_hash); // Add Hash Ruler _hash_html = add_hash_ruler(styled_hash); // Change Display // Hide Form Block dom_no_display_id("mushpup_form_parent"); // Display Hash Block dom_display_id("hash_stack", "block"); // Print Hash dom_set_id_html("hash_block", _hash_html); // *** RETURN return raw_hash; } // end Fx /*____________________________________________________________________________*/ // mushpup_reset_form /*____________________________________________________________________________*/ function mushpup_style_hash(raw_hash) { // *** DATA // Inline Styles var _hash0 = 'padding:4px 0; background:#eef; color:#fff; border-top:1px solid #F00; border-bottom:1px solid #00F; border-width:1px 0;'; var _hash1 = 'padding:4px 0; background:#fff; color:#eef; border-top:1px solid #F00; border-bottom:1px solid #00F; border-width:1px 0;'; // Return var styled_hash = ''; // *** MANIPULATE styled_hash += ( '' + raw_hash.substr(0,8) + "" ); styled_hash += ( '' + raw_hash.substr(8,8) + "" ); styled_hash += ( '' + raw_hash.substr(16,8) + "" ); styled_hash += ( '' + raw_hash.substr(24,8) + "" ); // *** RETURN return styled_hash; } // end Fx /*____________________________________________________________________________*/ // mushpup_show_passkey_confirm /*____________________________________________________________________________*/ function mushpup_show_passkey_confirm(show) { // *** DATA // Block IDs var id1 = "confirm_activate"; var id2 = "passkey_confirm"; var confirm_field = "passkey_confirm_input"; // Return // Void // *** MANIPULATE // Hide Activate Link // Show Input Field if ( show ) { dom_no_display_id(id1); dom_display_id(id2, "block"); dom_form_set_value(confirm_field, ""); } else { dom_no_display_id(id2); dom_display_id(id1, "block"); dom_form_set_value(confirm_field, "__^skip$__"); } // *** RETURN return; } // end Fx /*____________________________________________________________________________*/ // mushpup_reset_form /*____________________________________________________________________________*/ function mushpup_reset_form() { // *** DATA // *** MANIPULATE // Clear Form Fields dom_form_set_value("mushpup_passkey", ""); dom_form_set_value("site", ""); // Reset Toggles mushpup_show_passkey_confirm(0); dom_no_display_id("hash_stack"); // *** RETURN return; } // end Fx /*____________________________________________________________________________*/ // mushpup_reset_mirror /*____________________________________________________________________________*/ function mushpup_reset_mirror() { // *** DATA // *** MANIPULATE mushpup_reset_form(); dom_display_id("mushpup_form_parent"); // *** RETURN return; } // end Fx /*____________________________________________________________________________*/ // get_hash_display /*____________________________________________________________________________*/ function add_hash_ruler(the_hash) { // *** DATA // Return var hash_html = ''; // *** MANIPULATE // Label hash_html = '

your password is somewhere in here (copy and paste as needed):

'; // Case Open Div hash_html += '
'; // Top Ruler hash_html += '
'; hash_html += '
         1    1    2    
'; hash_html += '
>...5....0....5....0...>
'; hash_html += '
'; // Bottom Ruler hash_html += '
'; hash_html += '
    2    1    1         
'; hash_html += '
<...0....5....0....5...<
'; hash_html += '
'; // The Hash hash_html += '

' + the_hash + '

'; // Case Close Div hash_html += '
'; // *** RETURN return hash_html; } // end Fx /*____________________________________________________________________________*/ /*** LICENSE (http://www.opensource.org/licenses/bsd-license.php) Copyright (c) 2006, Tom Atwell (klenwell@gmail.com) Wired Jaw Technologies (http://www.wiredjawtech.com/) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Wired Jaw Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ______________________________________________________________________________*/