_binary From b7b347c1d7f5163fcffe85c87a3ddebafdb5d5a2 Mon Sep 17 00:00:00 2001
From: Akash Patel <akash3664@yahoo.com>
Date: Sun, 13 Apr 2014 00:43:15 -0700
Subject: implemented zkp

---
 configs/config.php                                 |   5 +-
 configs/createdb.php                               |  11 +
 controllers/admin_controller.php                   |  79 ++-
 controllers/components/accountaccess_component.php |   4 +-
 controllers/components/blogmixes_component.php     |   4 +-
 controllers/components/crawl_component.php         |   2 +-
 controllers/components/system_component.php        |   8 +-
 controllers/controller.php                         |   2 +-
 controllers/register_controller.php                |  94 ++-
 controllers/settings_controller.php                |   2 +-
 lib/locale_functions.php                           |   2 +-
 lib/upgrade_functions.php                          |  26 +
 locale/en-US/configure.ini                         |   9 +
 models/crawl_model.php                             |   2 +-
 models/group_model.php                             |   2 +-
 models/machine_model.php                           |   2 +-
 models/model.php                                   |  54 +-
 models/profile_model.php                           |  27 +-
 models/role_model.php                              |   2 +-
 models/signin_model.php                            |  57 +-
 models/source_model.php                            |   2 +-
 models/user_model.php                              |  34 +-
 scripts/basic.js                                   |  12 +-
 scripts/bigInt.js                                  | 647 +++++++++++++++++++++
 scripts/hashcaptcha.js                             | 201 -------
 scripts/mix.js                                     |   2 +-
 scripts/sha1.js                                    | 231 ++++++++
 scripts/zkp.js                                     | 210 +++++++
 tests/sha1_test.php                                |   2 +-
 views/crawlstatus_view.php                         |   2 +-
 views/elements/editmix_element.php                 |   2 +-
 views/elements/groupfeed_element.php               |   2 +-
 views/elements/manageaccount_element.php           |   2 +-
 views/elements/manageclassifiers_element.php       |   4 +-
 views/elements/managecrawls_element.php            |   2 +-
 views/elements/managegroups_element.php            |  12 +-
 views/elements/manageusers_element.php             |  18 +-
 views/elements/mixcrawls_element.php               |   4 +-
 views/elements/serversettings_element.php          |  16 +-
 views/elements/signin_element.php                  |   2 +-
 views/helpers/feeds_helper.php                     |   2 +-
 views/helpers/pagingtable_helper.php               |   2 +-
 views/layouts/web_layout.php                       |   2 +-
 views/recover_view.php                             |  76 ++-
 views/register_view.php                            |  17 +-
 views/settings_view.php                            |   2 +-
 views/signin_view.php                              |  20 +-
 47 files changed, 1557 insertions(+), 365 deletions(-)
 create mode 100644 scripts/bigInt.js
 create mode 100644 scripts/sha1.js
 create mode 100644 scripts/zkp.js

diff --git a/configs/config.php b/configs/config.php
index fbd2f81..d4a5f9e 100755
--- a/configs/config.php
+++ b/configs/config.php
@@ -104,7 +104,7 @@ if(MAINTENANCE_MODE && $_SERVER["SERVER_ADDR"] != $_SERVER["REMOTE_ADDR"]) {
 }
 
 if(!defined('WORK_DIRECTORY')) {
-/*+++ The next block of code is machine edited, change at
+/*+++ The next block of code is machine edited, change at 
 your own risk, please use configure web page instead +++*/
 define('WORK_DIRECTORY', '');
 /*++++++*/
@@ -158,6 +158,7 @@ if(file_exists(WORK_DIRECTORY.PROFILE_FILE_NAME)) {
     define('PROFILE', false);
     define('DBMS', 'sqlite3');
     define('CAPTCHA_MODE', HASH_CAPTCHA);
+    define('AUTHENTICATION_MODE', 'normal_authentication');
     define('DEBUG_LEVEL', NO_DEBUG_INFO);
     define('USE_FILECACHE', false);
     define('WEB_ACCESS', true);
@@ -645,4 +646,4 @@ define('GROUP_READ', 2);
  *   read items posted to the group as well as post new items
  */
 define('GROUP_READ_WRITE', 3);
-?>
+?>
\ No newline at end of file
diff --git a/configs/createdb.php b/configs/createdb.php
index ed6d18e..0eae730 100755
--- a/configs/createdb.php
+++ b/configs/createdb.php
@@ -101,6 +101,17 @@ $sql ="INSERT INTO USERS VALUES (".ROOT_ID.", 'admin', 'admin','root',
         "', '".crawlCrypt('root'.AUTH_KEY.$creation_time)."','$creation_time')";
 
 $db->execute($sql);
+
+$prime_number_part1 = '15521307879384003485799427706675365031492835831818386491713';
+$prime_number_part2 = '66591924563160025427690176245139603025';
+$prime_number = $prime_number_part1.$prime_number_part2;
+//default account is root without a password in case of ZKP system
+$sql ="INSERT INTO USERS_ZKP VALUES (".ROOT_ID.", 'admin', 'admin','root',
+        'root@dev.null', '$prime_number','".ACTIVE_STATUS."'
+        , '".crawlCrypt('root'.AUTH_KEY.$creation_time)."','$creation_time')";
+
+$db->execute($sql);
+
 // public account is an inactive account for used for public permissions
 //default account is root without a password
 $sql ="INSERT INTO USERS VALUES (".PUBLIC_USER_ID.", 'all', 'all','public',
diff --git a/controllers/admin_controller.php b/controllers/admin_controller.php
index 3565a3d..6eb7b97 100755
--- a/controllers/admin_controller.php
+++ b/controllers/admin_controller.php
@@ -62,6 +62,13 @@ foreach(glob(BASE_DIR."/lib/processors/*_processor.php") as $filename) {
 class AdminController extends Controller implements CrawlConstants
 {
     /**
+     * Number of Fiat-shamir iteration in case of zero knowledge authentication
+     * syste,
+     * @var int
+     */
+    const NUM_FIAT_SHAMIR_ITERATION = 10;
+
+    /**
      * Says which activities (roughly methods invoke from the web) this
      * controller will respond to (note: more activities will be loaded from
      * components)
@@ -88,6 +95,15 @@ class AdminController extends Controller implements CrawlConstants
     function processRequest()
     {
         $data = array();
+        $profile_model = $this->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
+        if($profile['AUTHENTICATION_MODE'] == 'zkp_authentication') {
+           if (!isset($_SESSION["COUNT"])) {
+                $_SESSION['COUNT'] = 1;
+           }
+        } else {
+                $_SESSION['COUNT'] = self::NUM_FIAT_SHAMIR_ITERATION;
+        }
 
         if(!PROFILE) {
             return $this->configureRequest();
@@ -116,32 +132,36 @@ class AdminController extends Controller implements CrawlConstants
                     tl('admin_controller_need_cookies')."</h1>');";
                 unset($_SESSION['USER_ID']);
             } else if ($this->checkSignin()){
-                $user_id = $this->model("signin")->getUserId(
-                    $this->clean($_REQUEST['u'], "string"));
-                $session = $this->model("user")->getUserSession($user_id);
-                if(is_array($session)) {
-                    $_SESSION = $session;
-                }
-
-                $_SESSION['USER_ID'] = $user_id;
-                $data[CSRF_TOKEN] = $this->generateCSRFToken(
-                    $_SESSION['USER_ID']);
-                // now don't want to use remote address anymore
-                $data['SCRIPT'] = "doMessage('<h1 class=\"red\" >".
-                    tl('admin_controller_login_successful')."</h1>')";
-                $data = array_merge($data, $this->processSession());
-                if(isset($data['INACTIVE'])) {
-                    $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
-                        tl('admin_controller_account_not_active')."</h1>');";
-                    $view = "signin";
+                $_SESSION['USER_NAME'] = $_REQUEST['u'];
+                if ($_SESSION['COUNT'] == self::NUM_FIAT_SHAMIR_ITERATION) {
+                    $_SESSION['COUNT'] = 1;
+                    $user_id = $this->model("signin")->getUserId(
+                        $this->clean($_REQUEST['u'], "string"));
+                    $session = $this->model("user")->getUserSession($user_id);
+                    if(is_array($session)) {
+                        $_SESSION = $session;
+                    }
+                    $_SESSION['USER_ID'] = $user_id;
+                    $data[CSRF_TOKEN] = $this->generateCSRFToken(
+                        $_SESSION['USER_ID']);
+                    // now don't want to use remote address anymore
+                    $data['SCRIPT'] = "doMessage('<h1 class=\"red\" >".
+                        tl('admin_controller_login_successful')."</h1>')";
+                    $data = array_merge($data, $this->processSession());
+                    if(isset($data['INACTIVE'])) {
+                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                            tl('admin_controller_account_not_active')."</h1>');";
+                        $view = "signin";
+                        unset($_SESSION['USER_ID']);
+                    }
+                    $view = "admin";
+                    }
+                } else {
+                    $_SESSION['COUNT'] = 1;
+                    $data['SCRIPT'] = "doMessage('<h1 class=\"red\" >".
+                        tl('admin_controller_login_failed')."</h1>');";
                     unset($_SESSION['USER_ID']);
                 }
-                $view = "admin";
-            } else {
-                $data['SCRIPT'] = "doMessage('<h1 class=\"red\" >".
-                    tl('admin_controller_login_failed')."</h1>');";
-                unset($_SESSION['USER_ID']);
-            }
         } else if($this->checkCSRFToken(CSRF_TOKEN, "config")) {
             $data['SCRIPT'] = "doMessage('<h1 class=\"red\" >".
                 tl('admin_controller_login_to_config')."</h1>')";
@@ -157,6 +177,15 @@ class AdminController extends Controller implements CrawlConstants
             $data["ADMIN"] = false;
         }
         if($view == 'signin') {
+            if (isset($_SESSION['salt_value'])) {
+                unset($_SESSION['salt_value']);
+            }
+            $profile_model = $this->model("profile");
+            $profile = $profile_model->getProfile(WORK_DIRECTORY);
+            if($profile['AUTHENTICATION_MODE'] == 'zkp_authentication') {
+                $_SESSION['salt_value'] = rand(0, 1);
+                $data['INCLUDE_SCRIPTS'] = array("zkp","bigInt","sha1");
+            }
             unset($_SESSION['USER_ID']);
             $data[CSRF_TOKEN] = $this->generateCSRFToken(
                 $_SERVER['REMOTE_ADDR']);
@@ -400,4 +429,4 @@ class AdminController extends Controller implements CrawlConstants
         }
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/controllers/components/accountaccess_component.php b/controllers/components/accountaccess_component.php
index faefde4..16ab3ba 100644
--- a/controllers/components/accountaccess_component.php
+++ b/controllers/components/accountaccess_component.php
@@ -311,7 +311,7 @@ class AccountaccessComponent extends Component
                                         $update = true;
                                     }
                                 }
-                                $data['CURRENT_USER'][$field] = 
+                                $data['CURRENT_USER'][$field] =
                                     $user[$upper_field];
                             } else if($_REQUEST["password"] !=
                                 $_REQUEST["retypepassword"]) {
@@ -1444,4 +1444,4 @@ class AccountaccessComponent extends Component
             }
         }
     }
-}
+}
\ No newline at end of file
diff --git a/controllers/components/blogmixes_component.php b/controllers/components/blogmixes_component.php
index d3019ba..5ec741b 100644
--- a/controllers/components/blogmixes_component.php
+++ b/controllers/components/blogmixes_component.php
@@ -321,7 +321,7 @@ class BlogmixesComponent extends Component implements CrawlConstants
             if($item['OWNER_ID'] == $user_id || $user_id == ROOT_ID) {
                 $page['MEMBER_ACCESS'] = GROUP_READ_WRITE;
             }
-            if(!$recent_found && $time - $item["PUBDATE"] < 
+            if(!$recent_found && $time - $item["PUBDATE"] <
                 5 * self::ONE_MINUTE) {
                 $recent_found = true;
                 $data['SCRIPT'] .= 'doUpdate();';
@@ -731,4 +731,4 @@ class BlogmixesComponent extends Component implements CrawlConstants
         }
         $data['SCRIPT'] .= ']; drawFragments();';
     }
-}
+}
\ No newline at end of file
diff --git a/controllers/components/crawl_component.php b/controllers/components/crawl_component.php
index 1bb6c10..63d73a1 100644
--- a/controllers/components/crawl_component.php
+++ b/controllers/components/crawl_component.php
@@ -1465,4 +1465,4 @@ class CrawlComponent extends Component implements CrawlConstants
             "switchSourceType()";
         return $data;
     }
-}
+}
\ No newline at end of file
diff --git a/controllers/components/system_component.php b/controllers/components/system_component.php
index da3b744..f4fa203 100644
--- a/controllers/components/system_component.php
+++ b/controllers/components/system_component.php
@@ -612,6 +612,12 @@ class SystemComponent extends Component
                 HASH_CAPTCHA =>
                    tl('serversettings_element_hash_captcha'),
             );
+        $data['AUTHENTICATION_MODES'] = array (
+                'normal_authentication' =>
+                   tl('serversettings_element_normal_authentication'),
+                'zkp_authentication' =>
+                   tl('serversettings_element_zkp_authentication'),
+        );
         $data['show_mail_info'] = "false";
         if(isset($data['REGISTRATION_TYPE']) &&
             in_array($data['REGISTRATION_TYPE'], array(
@@ -1046,4 +1052,4 @@ EOD;
      }
 
 
-}
+}
\ No newline at end of file
diff --git a/controllers/controller.php b/controllers/controller.php
index 854abb9..63a28a7 100755
--- a/controllers/controller.php
+++ b/controllers/controller.php
@@ -560,4 +560,4 @@ abstract class Controller
         return true;
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/controllers/register_controller.php b/controllers/register_controller.php
index ede9a69..348bfd2 100755
--- a/controllers/register_controller.php
+++ b/controllers/register_controller.php
@@ -190,6 +190,8 @@ class RegisterController extends Controller implements CrawlConstants
      */
     function processRequest()
     {
+        $profile_model = $this->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
         $visitor_model = $this->model("visitor");
         if(isset($_SESSION['USER_ID'])) {
             $user = $_SESSION['USER_ID'];
@@ -224,8 +226,10 @@ class RegisterController extends Controller implements CrawlConstants
             'processAccountData', 'createAccount', $data);
         $data["check_fields"] = array("user");
         unset($data["check_user"]);
-        for($i = 0; $i < self::NUM_CAPTCHA_QUESTIONS; $i++) {
-            $data["check_fields"][] = "question_$i";
+        if($profile['CAPTCHA_MODE'] == TEXT_CAPTCHA) {
+            for($i = 0; $i < self::NUM_CAPTCHA_QUESTIONS; $i++) {
+                $data["check_fields"][] = "question_$i";
+            }
         }
         $this->preactivityPrerequisiteCheck($activity,
             'processRecoverData', 'recoverPassword', $data);
@@ -250,6 +254,21 @@ class RegisterController extends Controller implements CrawlConstants
             $visitor_model->updateVisitor(
                 $_SERVER['REMOTE_ADDR'], "captcha_time_out");
         }
+        if (isset($_SESSION['salt_value'])) {
+                unset($_SESSION['salt_value']);
+        }
+        if($profile['AUTHENTICATION_MODE'] == 'zkp_authentication') {
+            $_SESSION['salt_value'] = rand(0, 1);
+            $_SESSION['COUNT'] = 1;
+            $data['INCLUDE_SCRIPTS'] = array("sha1","zkp","bigInt");
+        }
+        if($profile['CAPTCHA_MODE'] == HASH_CAPTCHA) {
+            if(isset($data['INCLUDE_SCRIPTS'])) {
+                array_push($data['INCLUDE_SCRIPTS'], "hashcaptcha");
+            } else {
+               $data['INCLUDE_SCRIPTS'] = array("sha1","hashcaptcha");
+            }
+        }
         //used to ensure that we have sessions active
         $_SESSION['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
         $this->displayView($view, $data);
@@ -439,6 +458,8 @@ class RegisterController extends Controller implements CrawlConstants
      */
     function processRecoverData()
     {
+        $profile_model = $this->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
         $data = array();
         $this->getCleanFields($data);
         $data['SCRIPT'] = "";
@@ -453,11 +474,13 @@ class RegisterController extends Controller implements CrawlConstants
             return $data;
         }
         $session = $user_model->getUserSession($user["USER_ID"]);
-        if(!isset($session['RECOVERY']) ||
-            !isset($session['RECOVERY_ANSWERS'])) {
-            $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+        if($profile['CAPTCHA_MODE'] == TEXT_CAPTCHA) {
+            if(!isset($session['RECOVERY']) ||
+                !isset($session['RECOVERY_ANSWERS'])) {
+                $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                 tl('register_controller_account_recover_fail')."</h1>');";
-            return $data;
+                return $data;
+            }
         }
         $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
             tl('register_controller_account_recover_email')."</h1>');";
@@ -608,7 +631,7 @@ class RegisterController extends Controller implements CrawlConstants
         $visitor_model = $this->model("visitor");
         $clear = false;
         if($profile['CAPTCHA_MODE'] == HASH_CAPTCHA) {
-            $data['INCLUDE_SCRIPTS'] = array("hashcaptcha");
+            $data['INCLUDE_SCRIPTS'] = array("hashcaptcha","sha1");
         }
         if($profile['CAPTCHA_MODE'] == TEXT_CAPTCHA) {
             $num_captchas = self::NUM_CAPTCHA_QUESTIONS;
@@ -769,8 +792,20 @@ class RegisterController extends Controller implements CrawlConstants
             self::NUM_CAPTCHA_CHOICES; $i++) {
             $data["question_$i"] = "-1";
         }
+        if($profile['AUTHENTICATION_MODE'] == 'zkp_authentication') {
+            $data['AUTHENTICATION_MODE'] = 'zkp_authentication';
+            $data['INCLUDE_SCRIPTS'] = array("sha1","zkp","bigInt");
+         }
+         else
+         {
+            $data['AUTHENTICATION_MODE'] = 'normal_authentication';
+         }
         if($profile['CAPTCHA_MODE'] == HASH_CAPTCHA) {
-            $data['INCLUDE_SCRIPTS'] = array("hashcaptcha");
+            if(isset($data['INCLUDE_SCRIPTS'])) {
+                array_push($data['INCLUDE_SCRIPTS'],"hashcaptcha");
+            } else {
+                $data['INCLUDE_SCRIPTS'] = array("hashcaptcha","sha1");
+            }
             $time = time();
             $_SESSION["request_time"] = $time;
             $_SESSION["level"] = self::HASH_CAPTCHA_LEVEL;
@@ -1013,6 +1048,7 @@ class RegisterController extends Controller implements CrawlConstants
      */
     function getCleanFields(&$data)
     {
+        
         $fields = $this->register_fields;
         if(isset($data["check_fields"])) {
             $fields = $data["check_fields"];
@@ -1050,25 +1086,29 @@ class RegisterController extends Controller implements CrawlConstants
             $data["PASSWORD"] = "";
             $data["REPASSWORD"] = "";
         }
-        $num_questions = self::NUM_CAPTCHA_QUESTIONS +
-            self::NUM_RECOVERY_QUESTIONS;
-        $num_captchas = self::NUM_CAPTCHA_QUESTIONS;
-        for($i = 0; $i < $num_questions; $i++) {
-            $field = "question_$i";
-            if(!in_array($field, $fields)) {
-                continue;
-            }
-            $captchas = isset($_SESSION['CAPTCHAS'][$i]) ?
-                $_SESSION['CAPTCHAS'][$i] : array();
-            $recovery = isset($_SESSION['RECOVERY'][$i  - $num_captchas]) ?
-                $_SESSION['RECOVERY'][$i  - $num_captchas] : array();
-            $current_dropdown = ($i< $num_captchas) ?
-                $captchas : $recovery;
-            if(!isset($_REQUEST[$field]) || $_REQUEST[$field] == "-1" ||
-                !in_array($_REQUEST[$field], $current_dropdown)) {
-                $missing[] = $field;
-            } else {
-                $data[$field] = $_REQUEST[$field];
+        $profile_model = $this->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
+        if($profile['CAPTCHA_MODE'] == TEXT_CAPTCHA) {
+            $num_questions = self::NUM_CAPTCHA_QUESTIONS +
+                self::NUM_RECOVERY_QUESTIONS;
+            $num_captchas = self::NUM_CAPTCHA_QUESTIONS;
+            for($i = 0; $i < $num_questions; $i++) {
+                $field = "question_$i";
+                if(!in_array($field, $fields)) {
+                    continue;
+                }
+                $captchas = isset($_SESSION['CAPTCHAS'][$i]) ?
+                    $_SESSION['CAPTCHAS'][$i] : array();
+                $recovery = isset($_SESSION['RECOVERY'][$i  - $num_captchas]) ?
+                    $_SESSION['RECOVERY'][$i  - $num_captchas] : array();
+                $current_dropdown = ($i< $num_captchas) ?
+                    $captchas : $recovery;
+                if(!isset($_REQUEST[$field]) || $_REQUEST[$field] == "-1" ||
+                    !in_array($_REQUEST[$field], $current_dropdown)) {
+                    $missing[] = $field;
+                } else {
+                    $data[$field] = $_REQUEST[$field];
+                }
             }
         }
         $data['MISSING'] = $missing;
diff --git a/controllers/settings_controller.php b/controllers/settings_controller.php
index d6d2120..e1d9f71 100755
--- a/controllers/settings_controller.php
+++ b/controllers/settings_controller.php
@@ -149,4 +149,4 @@ class SettingsController extends Controller
 
 }
 
-?>
+?>
\ No newline at end of file
diff --git a/lib/locale_functions.php b/lib/locale_functions.php
index caa3b6d..902190a 100755
--- a/lib/locale_functions.php
+++ b/lib/locale_functions.php
@@ -496,4 +496,4 @@ function formatDateByLocale($timestamp, $locale_tag)
             return date("F d Y H:i", intval($timestamp));
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/lib/upgrade_functions.php b/lib/upgrade_functions.php
index 5d99653..14edd5b 100644
--- a/lib/upgrade_functions.php
+++ b/lib/upgrade_functions.php
@@ -145,6 +145,7 @@ function upgradeDatabaseVersion2(&$db)
 {
     $db->execute("UPDATE VERSION SET ID=2 WHERE ID=1");
     $db->execute("ALTER TABLE USERS ADD UNIQUE ( USER_NAME )" );
+    $db->execute("ALTER TABLE USERS_ZKP ADD UNIQUE ( USER_NAME )" );
     $db->execute("INSERT INTO LOCALE VALUES (
         17, 'kn', 'ಕನ್ನಡ', 'lr-tb')");
     $db->execute("INSERT INTO LOCALE VALUES (
@@ -600,11 +601,18 @@ function upgradeDatabaseVersion19(&$db)
         "DB_PASSWORD" => DB_PASSWORD);
     $sql = "ALTER TABLE USERS RENAME TO USER_OLD";
     $db->execute($sql);
+    $sql = "ALTER TABLE USERS_ZKP RENAME TO USER_ZKP_OLD";
+    $db->execute($sql);
     $auto_increment = $db->autoIncrement($dbinfo);
     $db->execute("CREATE TABLE USERS(USER_ID INTEGER PRIMARY KEY $auto_increment,
         FIRST_NAME VARCHAR(16), LAST_NAME VARCHAR(16),
         USER_NAME VARCHAR(16) UNIQUE, EMAIL VARCHAR(60),
         PASSWORD CHAR(60), STATUS INTEGER, HASH CHAR(60))");
+    $db->execute( "CREATE TABLE USERS_ZKP(USER_ID $serial
+         PRIMARY KEY $auto_increment,FIRST_NAME VARCHAR(16),
+         LAST_NAME VARCHAR(16), USER_NAME VARCHAR(16) UNIQUE,
+         EMAIL VARCHAR(60), PASSWORD CHAR(200),
+         STATUS INTEGER, HASH CHAR(300),CREATION_TIME VARCHAR(20))");
     $sql = "SELECT USER_ID, USER_NAME FROM USER_OLD";
     $result = $db->execute($sql);
     while($row = $db->fetchArray($result)) {
@@ -620,11 +628,29 @@ function upgradeDatabaseVersion19(&$db)
             $creation_time."')";
         $db->execute($sql);
     }
+    $sql = "SELECT USER_ID, USER_NAME FROM USER_ZKP_OLD";
+    $result = $db->execute($sql);
+    while($row = $db->fetchArray($result)) {
+        $status = ($row['USER_NAME'] == 'root') ? ACTIVE_STATUS :
+            INACTIVE_STATUS;
+        $creation_time = microTimestamp();
+        $sql = "INSERT INTO USER_ZKP (USER_ID, USER_NAME, FIRST_NAME, LAST_NAME,
+            EMAIL, PASSWORD, STATUS, HASH)
+            VALUES ('{$row['USER_ID']}', '{$row['USER_NAME']}',
+            '{$row['FIRST_NAME']}', '{$row['LAST_NAME']}', '{$row['EMAIL']}',
+            '1552130787938400348579942770667536503149283583181838649171366591
+            924563160025427690176245139603025', '".$status."', '".
+            crawlCrypt($row['USER_NAME'].AUTH_KEY.$creation_time)."', '".
+            $creation_time."')";
+        $db->execute($sql);
+    }
     $db->disconnect();
     $db->connect();
     $db->dbname = NULL;
     $sql = "DROP TABLE USER_OLD";
     $db->execute($sql);
+    $sql = "DROP TABLE USER_ZKP_OLD";
+    $db->execute($sql);
 
 }
 
diff --git a/locale/en-US/configure.ini b/locale/en-US/configure.ini
index 55b3fd0..5c15c40 100755
--- a/locale/en-US/configure.ini
+++ b/locale/en-US/configure.ini
@@ -882,6 +882,12 @@ serversettings_element_text_captcha = "Text Captcha"
 ; system_component.php line: 612
 serversettings_element_hash_captcha = "Hash Captcha"
 ;
+; system_component.php line: 610
+serversettings_element_normal_authentication = "Normal Authentication"
+;
+; system_component.php line: 612
+serversettings_element_zkp_authentication = "ZKP Authentication"
+;
 ; system_component.php line: 716
 system_component_configure_use_absolute_path = "Must use an Absolute path for Work Directory"
 ;
@@ -2708,6 +2714,9 @@ serversettings_element_proxy_servers = "Proxy Servers (One per line. Format: add
 ; serversettings_element.php line: 243
 serversettings_element_captcha_setting = "Captcha Setting"
 ;
+; serversettings_element.php line: 258
+serversettings_element_authentication_mode = "Authentication Mode"
+;
 ; serversettings_element.php line: 255
 serversettings_element_submit = "Submit"
 ;
diff --git a/models/crawl_model.php b/models/crawl_model.php
index 48d3241..75cfc3c 100755
--- a/models/crawl_model.php
+++ b/models/crawl_model.php
@@ -1472,4 +1472,4 @@ EOT;
      }
 
 }
-?>
+?>
\ No newline at end of file
diff --git a/models/group_model.php b/models/group_model.php
index e8bcbe2..e91bd93 100644
--- a/models/group_model.php
+++ b/models/group_model.php
@@ -688,4 +688,4 @@ class GroupModel extends Model
         return $row['NUM'];
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/models/machine_model.php b/models/machine_model.php
index 41e6a39..1a05f17 100644
--- a/models/machine_model.php
+++ b/models/machine_model.php
@@ -339,4 +339,4 @@ class MachineModel extends Model
     }
 }
 
- ?>
+ ?>
\ No newline at end of file
diff --git a/models/model.php b/models/model.php
index e1ffd43..da07f31 100755
--- a/models/model.php
+++ b/models/model.php
@@ -443,7 +443,8 @@ class Model implements CrawlConstants
     function getUserId($username)
     {
         $db = $this->db;
-        $sql = "SELECT USER_ID FROM USERS WHERE
+        $user_table_name = $this->getUserTableName();
+        $sql = "SELECT USER_ID FROM $user_table_name WHERE
             UPPER(USER_NAME) = UPPER(?) ". $db->limitOffset(1);
         $result = $db->execute($sql, array($username));
         if(!$result) {
@@ -454,6 +455,55 @@ class Model implements CrawlConstants
         return $user_id;
     }
 
+    /** Dynamic loader for Model objects
+     *
+     * @param string $model name of model to return
+     */
+    function model($model)
+    {
+        if(!isset($this->model_instances[$model])) {
+            if(file_exists(APP_DIR."/models/".$model."_model.php")){
+                require_once APP_DIR."/models/".$model."_model.php";
+            } else {
+                require_once BASE_DIR."/models/".$model."_model.php";
+            }
+            $model_name = ucfirst($model)."Model";
+            $this->model_instances[$model] = new $model_name();
+        }
+        return $this->model_instances[$model];
+    }
+
+    /**
+     * Get the authentication mode from the profile model
+     *
+     * @param string name of the authentication mode
+     */
+    function getAuthenticationMode()
+    {
+        $profile_model = $this->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
+        return $profile['AUTHENTICATION_MODE'];
+    }
+
+     /**
+     * Get the user table name based on the authentication mode.
+     * If it is a normal authentication then this method returns
+     * USERS and if the authentication mode is a zkp authentication
+     * it returns USERS_ZKP
+     *
+     * @param string name of user table
+     */
+    function getUserTableName()
+    {
+        $authentication_mode = $this->getAuthenticationMode();
+        if($authentication_mode == 'zkp_authentication') {
+            $user_table_name = 'USERS_ZKP';
+        }else {
+            $user_table_name = 'USERS';
+        }
+        return $user_table_name;
+    }
+
     /**
      *  Creates the WHERE and ORDER BY clauses for a query of a Yioop
      *  table such as USERS, ROLE, GROUP, which have associated search web
@@ -584,4 +634,4 @@ class Model implements CrawlConstants
         return $rows;
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/models/profile_model.php b/models/profile_model.php
index 240d9a7..37ec95e 100755
--- a/models/profile_model.php
+++ b/models/profile_model.php
@@ -49,17 +49,17 @@ require_once(BASE_DIR.'/lib/url_parser.php');
  */
 class ProfileModel extends Model
 {
-    var $profile_fields = array('API_ACCESS', 'AUTH_KEY', 'CACHE_LINK',
-        'CAPTCHA_MODE','DEBUG_LEVEL', 'DESCRIPTION_WEIGHT', 'DB_HOST', 'DBMS',
-        'DB_NAME','DB_PASSWORD', 'DB_USER', 'DEFAULT_LOCALE', 'GROUP_ITEM',
-        'IN_LINK','IP_LINK', 'LINK_WEIGHT', 'MAIL_PASSWORD', 'MAIL_SECURITY',
-        'MAIL_SENDER', 'MAIL_SERVER', 'MAIL_SERVERPORT', 'MAIL_USERNAME',
-        'MEMCACHE_SERVERS', 'MIN_RESULTS_TO_GROUP', 'NAME_SERVER', 'NEWS_MODE',
-        'PROXY_SERVERS', 'REGISTRATION_TYPE', 'ROBOT_DESCRIPTION',
-        'ROBOT_INSTANCE', 'RSS_ACCESS', 'SERVER_ALPHA', 'SIGNIN_LINK',
-        'SIMILAR_LINK', 'SUBSEARCH_LINK', 'TITLE_WEIGHT', 'TOR_PROXY',
-        'USE_FILECACHE', 'USE_MAIL_PHP', 'USE_MEMCACHE', 'USE_PROXY',
-        'USER_AGENT_SHORT', 'WEB_URI', 'WEB_ACCESS', 'WORD_SUGGEST'
+    var $profile_fields = array('API_ACCESS', 'AUTH_KEY','AUTHENTICATION_MODE',
+        'CACHE_LINK','CAPTCHA_MODE','DEBUG_LEVEL', 'DESCRIPTION_WEIGHT',
+        'DB_HOST', 'DBMS', 'DB_NAME','DB_PASSWORD', 'DB_USER', 'DEFAULT_LOCALE',
+        'GROUP_ITEM','IN_LINK','IP_LINK', 'LINK_WEIGHT', 'MAIL_PASSWORD',
+        'MAIL_SECURITY', 'MAIL_SENDER', 'MAIL_SERVER', 'MAIL_SERVERPORT',
+        'MAIL_USERNAME','MEMCACHE_SERVERS', 'MIN_RESULTS_TO_GROUP',
+        'NAME_SERVER', 'NEWS_MODE','PROXY_SERVERS', 'REGISTRATION_TYPE',
+        'ROBOT_DESCRIPTION','ROBOT_INSTANCE', 'RSS_ACCESS', 'SERVER_ALPHA',
+        'SIGNIN_LINK','SIMILAR_LINK', 'SUBSEARCH_LINK', 'TITLE_WEIGHT',
+        'TOR_PROXY','USE_FILECACHE', 'USE_MAIL_PHP', 'USE_MEMCACHE',
+        'USE_PROXY','USER_AGENT_SHORT', 'WEB_URI', 'WEB_ACCESS', 'WORD_SUGGEST'
         );
     /**
      *  {@inheritdoc}
@@ -335,6 +335,11 @@ EOT;
                 USER_NAME VARCHAR(16) UNIQUE, EMAIL VARCHAR(60),
                 PASSWORD CHAR(60), STATUS INTEGER, HASH CHAR(60),
                 CREATION_TIME VARCHAR(20))",
+            "CREATE TABLE USERS_ZKP(USER_ID $serial PRIMARY KEY $auto_increment,
+                FIRST_NAME VARCHAR(16), LAST_NAME VARCHAR(16),
+                USER_NAME VARCHAR(16) UNIQUE, EMAIL VARCHAR(60),
+                PASSWORD CHAR(200), STATUS INTEGER, HASH CHAR(300),
+                CREATION_TIME VARCHAR(20))",
             "CREATE TABLE USER_GROUP (USER_ID INTEGER , GROUP_ID INTEGER,
                    STATUS INTEGER, JOIN_DATE NUMERIC(11),
                    PRIMARY KEY (GROUP_ID, USER_ID) )",
diff --git a/models/role_model.php b/models/role_model.php
index 361b29b..aaf2f42 100644
--- a/models/role_model.php
+++ b/models/role_model.php
@@ -329,4 +329,4 @@ class RoleModel extends Model
         $this->db->execute($sql, array($role_id, $activity_id));
     }
 }
- ?>
+ ?>
\ No newline at end of file
diff --git a/models/signin_model.php b/models/signin_model.php
index bd50044..31c1997 100755
--- a/models/signin_model.php
+++ b/models/signin_model.php
@@ -50,6 +50,37 @@ require_once BASE_DIR."/lib/utility.php";
 class SigninModel extends Model
 {
     /**
+     * Checks that a username and password pair is valid in case
+     * of zero knowledge authentication system.
+     *
+     * @param string $username the username to check
+     * @param string $database_username the username stored in database
+     * @param string $database_password the password stored in database
+     * @return bool  where the password is that of the given user
+     */
+    function checkValidSigninForZKP($username,$database_username,
+        $database_password)
+    {
+        $x1 =  $_REQUEST['x1'];
+        $y1 =  $_REQUEST['y1'];
+        $n = "4911896143611633780682402453849989800775189204252065".
+             "7264082207290936669351692953333549721159585615965418".
+             "82926741138174142872698595829944178957090296779606642".
+             "580976458630868510407440881709556568052691";
+        $v = $database_password;
+        $e = $_SESSION['salt_value'];
+        $rp = bcmul($x1, bcmod(bcpow($v, $e), $n));
+        $lp = bcmul($y1, $y1);
+        if ($username == $database_username && bccomp($rp, $lp) == 0) {
+            $_SESSION['COUNT'] = $_SESSION['COUNT'] + 1;
+            return true;
+        } else {
+            unset( $_SESSION['COUNT']);
+            return false;
+        }
+    }
+
+    /**
      * Checks that a username password pair is valid
      *
      * @param string $username the username to check
@@ -60,7 +91,8 @@ class SigninModel extends Model
     function checkValidSignin($username, $password)
     {
         $db = $this->db;
-        $sql = "SELECT USER_NAME, PASSWORD FROM USERS ".
+        $user_table_name = $this->getUserTableName();
+        $sql = "SELECT USER_NAME, PASSWORD FROM $user_table_name ".
             "WHERE USER_NAME = ? " . $db->limitOffset(1);
         $i = 0;
         do {
@@ -74,7 +106,11 @@ class SigninModel extends Model
             return false;
         }
         $row = $db->fetchArray($result);
-
+        $authentication_mode = $this->getAuthenticationMode();
+        if($authentication_mode == 'zkp_authentication') {
+            return $this->checkValidSigninForZKP($username,$row['USER_NAME'],
+                $row['PASSWORD']);
+        }
         return ($username == $row['USER_NAME'] &&
             crawlCrypt($password, $row['PASSWORD']) == $row['PASSWORD']) ;
     }
@@ -87,11 +123,11 @@ class SigninModel extends Model
      * @return bool  where the email is that of the given user
      *      (or at least hashes to the same thing)
      */
-
     function checkValidEmail($username, $email)
     {
         $db = $this->db;
-        $sql = "SELECT USER_NAME, EMAIL FROM USERS ".
+        $user_table_name = $this->getUserTableName();
+        $sql = "SELECT USER_NAME, EMAIL FROM $user_table_name ".
             "WHERE USER_NAME = ? " . $db->limitOffset(1);
 
         $result = $db->execute($sql, array($username));
@@ -112,7 +148,8 @@ class SigninModel extends Model
    function getUserName($user_id)
    {
         $db = $this->db;
-        $sql = "SELECT USER_NAME FROM USERS WHERE USER_ID = ? " .
+        $user_table_name = $this->getUserTableName();
+        $sql = "SELECT USER_NAME FROM $user_table_name WHERE USER_ID = ? " .
             $db->limitOffset(1);
         $result = $db->execute($sql, array($user_id));
         $row = $db->fetchArray($result);
@@ -129,7 +166,8 @@ class SigninModel extends Model
    function getEmail($user_id, $limit = 1)
    {
         $db = $this->db;
-        $sql = "SELECT EMAIL FROM USERS WHERE
+        $user_table_name = $this->getUserTableName();
+        $sql = "SELECT EMAIL FROM $user_table_name WHERE
             USER_ID = ?  " . $db->limitOffset($limit);
         $result = $db->execute($sql, array($user_id));
         $row = $db->fetchArray($result);
@@ -144,10 +182,10 @@ class SigninModel extends Model
      *  @param string $email new email for user
      *  @return bool update successful or not.
      */
-
     function changeEmail($username, $email)
     {
-        $sql = "UPDATE USERS SET EMAIL= ? WHERE USER_NAME = ? ";
+        $user_table_name = $this->getUserTableName();
+        $sql = "UPDATE $user_table_name SET EMAIL= ? WHERE USER_NAME = ? ";
         $result = $this->db->execute($sql, array($email, $username));
         return $result != false;
     }
@@ -161,7 +199,8 @@ class SigninModel extends Model
      */
     function changePassword($username, $password)
     {
-        $sql = "UPDATE USERS SET PASSWORD=? WHERE USER_NAME = ? ";
+        $user_table_name = $this->getUserTableName();
+        $sql = "UPDATE $user_table_name SET PASSWORD=? WHERE USER_NAME = ? ";
         $result = $this->db->execute($sql,
             array(crawlCrypt($password), $username) );
         return $result != false;
diff --git a/models/source_model.php b/models/source_model.php
index 2e5865c..20852d2 100644
--- a/models/source_model.php
+++ b/models/source_model.php
@@ -485,4 +485,4 @@ class SourceModel extends Model
         return $meta_ids;
     }
 }
- ?>
+ ?>
\ No newline at end of file
diff --git a/models/user_model.php b/models/user_model.php
index 586446c..5e25593 100755
--- a/models/user_model.php
+++ b/models/user_model.php
@@ -52,7 +52,7 @@ class UserModel extends Model
     /**
      * @var string
      */
-    var $from_tables = "USERS";
+    var $from_table = "USER";
 
     /**
      *  @var string
@@ -214,8 +214,9 @@ class UserModel extends Model
      */
     function getUsername($user_id)
     {
+        $user_table_name = $this->getUserTableName();
         $db = $this->db;
-        $sql = "SELECT USER_NAME FROM USERS WHERE USER_ID=?";
+        $sql = "SELECT USER_NAME FROM $user_table_name WHERE USER_ID=?";
         $result = $db->execute($sql, array($user_id));
         $row = $db->fetchArray($result);
         return $row['USER_NAME'];
@@ -229,8 +230,9 @@ class UserModel extends Model
      */
     function getUserStatus($user_id)
     {
+        $user_table_name = $this->getUserTableName();
         $db = $this->db;
-        $sql = "SELECT STATUS FROM USERS WHERE USER_ID=?";
+        $sql = "SELECT STATUS FROM $user_table_name WHERE USER_ID=?";
         $result = $db->execute($sql, array($user_id));
         $row = $db->fetchArray($result);
         return $row['STATUS'];
@@ -244,8 +246,9 @@ class UserModel extends Model
      */
     function getUser($username)
     {
+        $user_table_name = $this->getUserTableName();
         $db = $this->db;
-        $sql = "SELECT * FROM USERS WHERE UPPER(USER_NAME) = UPPER(?) " .
+        $sql = "SELECT * FROM $user_table_name WHERE UPPER(USER_NAME) = UPPER(?) " .
             $db->limitOffset(1);
         $result = $db->execute($sql, array($username));
         if(!$result) {
@@ -265,8 +268,9 @@ class UserModel extends Model
      */
     function getUserByEmailTime($email, $creation_time)
     {
+        $user_table_name = $this->getUserTableName();
         $db = $this->db;
-        $sql = "SELECT * FROM USERS WHERE UPPER(EMAIL) = UPPER(?)
+        $sql = "SELECT * FROM $user_table_name WHERE UPPER(EMAIL) = UPPER(?)
             AND CREATION_TIME=? " . $db->limitOffset(1);
         $result = $db->execute($sql, array($email, $creation_time));
         if(!$result) {
@@ -283,12 +287,13 @@ class UserModel extends Model
      */
     function updateUserStatus($user_id, $status)
     {
+        $user_table_name = $this->getUserTableName();
         $db = $this->db;
         if(!in_array($status, array(ACTIVE_STATUS, INACTIVE_STATUS,
             BANNED_STATUS))) {
             return;
         }
-        $sql = "UPDATE USERS SET STATUS=? WHERE USER_ID=?";
+        $sql = "UPDATE $user_table_name SET STATUS=? WHERE USER_ID=?";
         $db->execute($sql, array($status, $user_id));
     }
 
@@ -307,12 +312,17 @@ class UserModel extends Model
         $email='', $status = ACTIVE_STATUS)
     {
         $creation_time = microTimestamp();
+        $user_table_name = $this->getUserTableName();
+        if($user_table_name=='USERS')
+        {
+            $password = crawlCrypt($password) ;
+        }
         $db = $this->db;
-        $sql = "INSERT INTO USERS(FIRST_NAME, LAST_NAME,
+        $sql = "INSERT INTO $user_table_name(FIRST_NAME, LAST_NAME,
             USER_NAME, EMAIL, PASSWORD, STATUS, HASH, CREATION_TIME) VALUES (
             ?, ?, ?, ?, ?, ?, ?, ?)";
         $result = $db->execute($sql, array($firstname, $lastname,
-            $username, $email, crawlCrypt($password), $status,
+            $username, $email, $password, $status,
             crawlCrypt($username.AUTH_KEY.$creation_time), $creation_time));
         if(!$user_id = $this->getUserId($username)) {
             return false;
@@ -348,7 +358,8 @@ class UserModel extends Model
             $sql = "DELETE FROM USER_SESSION WHERE USER_ID=?";
             $result = $db->execute($sql, array($user_id));
         }
-        $sql = "DELETE FROM USERS WHERE USER_ID=?";
+        $user_table_name = $this->getUserTableName();
+        $sql = "DELETE FROM $user_table_name WHERE USER_ID=?";
         $result = $db->execute($sql, array($user_id));
     }
 
@@ -360,10 +371,11 @@ class UserModel extends Model
      */
     function updateUser($user)
     {
+        $user_table_name = $this->getUserTableName();
         $user_id = $user['USER_ID'];
         unset($user['USER_ID']);
         unset($user['USER_NAME']);
-        $sql = "UPDATE USERS SET ";
+        $sql = "UPDATE $user_table_name SET ";
         $comma ="";
         $params = array();
         foreach($user as $field => $value) {
@@ -376,4 +388,4 @@ class UserModel extends Model
         $this->db->execute($sql, $params);
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/scripts/basic.js b/scripts/basic.js
index 80e840a..d73536e 100755
--- a/scripts/basic.js
+++ b/scripts/basic.js
@@ -102,6 +102,16 @@ function getPage(tag, url)
 }
 
 /*
+ *  Shorthand for document.createElement()
+ *
+ *  @param String input type of the element
+ */
+function ce(input)
+{
+    return document.createElement(input);
+}
+
+/*
  *  Shorthand for document.getElementById()
  *
  *  @param String id  the id of the DOM element one wants
@@ -153,4 +163,4 @@ function toggleDisplay(id)
         value = "block";
     }
     obj.style.display = value;
-}
+}
\ No newline at end of file
diff --git a/scripts/bigInt.js b/scripts/bigInt.js
new file mode 100644
index 0000000..98e62ce
--- /dev/null
+++ b/scripts/bigInt.js
@@ -0,0 +1,647 @@
+/**
+ *  SeekQuarry/Yioop --
+ *  Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ *  Copyright (C) 2009 - 2014  Chris Pollett chris@pollett.org
+ *
+ *  LICENSE:
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  END LICENSE
+ *
+ * @author Chris Pollett chris@pollett.org
+ * @package seek_quarry
+ * @subpackage javascript
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2009 - 2014
+ * @filesource
+ */
+
+/*
+ * Constant for Number of bits per element
+ */
+var bits_per_element=15;
+
+/*
+ * Constant to mask the overflow value
+ */
+var mask=32767;
+
+/*
+ * Constant to define radix
+ */
+var radix=mask+1;
+
+/*
+ *  To add bigInt and int number
+ *
+ *  @param bigInt x first operand
+ *  @param int n second operand
+ *  @return bigInt result
+ */
+function addInteger(x,n)
+{
+  var new_x=expandBigInt(x,x.length+1);
+  addBigIntToInt(new_x,n);
+  return trimBigInt(new_x,1);
+}
+
+/*
+ *  To return the bigInt with given number of leading zeroes
+ *
+ *  @param bigInt x first operand
+ *  @param int k expected number of leading zeroes
+ *  @return bigInt result
+ */
+function trimBigInt(x,k)
+{
+  var i=x.length;
+  while(i>0 && !x[i-1]){
+      i--;
+  }
+  var y=new Array(i+k);
+  copyBigIntToBigInt(y,x);
+  return y;
+}
+
+/*
+ *  To expand the bigInt with atleast n elements.
+ *  adding zeroes if needed
+ *
+ *  @param bigInt x first operand
+ *  @param int n expected number of elements
+ *  @return bigInt result
+ */
+function expandBigInt(x,n)
+{
+  var bits = (x.length>n ? x.length : n)*bits_per_element;
+  var ans=int2bigInt(0,bits,0);
+  copyBigIntToBigInt(ans,x);
+  return ans;
+}
+
+/*
+ *  To convert normal int to BigInt.Pad the array with leading zeros so
+ *   that it has at least minSize elements.
+ *
+ *  @param int t input number
+ *  @param int bits expected number of bits
+ *  @param int minSize minimum size of the BigInt.
+ *  @return Array stores the bigInt in bits_per_element-bit chunks,
+ *  little endian
+ */
+function int2bigInt(t,bits,minSize)
+{
+  var k=Math.ceil(bits/bits_per_element)+1;
+  var buff=new Array(k);
+  copyBigIntToInt(buff,t);
+  return buff;
+}
+
+/*
+ *  To copy one bigInt to another bigInt
+ *  x must be an array at least as big as y (not counting the leading zeros in y).
+ *  @param bigInt x input number
+ *  @param bigInt bits expected number of bits
+ *  @return bigInt result
+ */
+function copyBigIntToBigInt(x,y)
+{
+  var k=x.length<y.length ? x.length : y.length;
+  for (var i=0;i<k;i++)
+    x[i]=y[i];
+  for (var i=k;i<x.length;i++)
+    x[i]=0;
+}
+
+/*
+ *  To copy one bigInt to another int
+ *
+ *  @param bigInt x input number
+ *  @param  int n input number
+ *  @return bigInt result
+ */
+function copyBigIntToInt(x,n)
+{
+  var i,c;
+  for (c=n,i=0;i<x.length;i++) {
+    x[i]=c & mask;
+    c>>=bits_per_element;
+  }
+}
+
+/*
+ *  To perform x=x+n where x is a bigInt and n is an integer.
+ *
+ *  @param bigInt x input number
+ *  @param  int n input number
+ *  @return bigInt result of the summation
+ */
+function addBigIntToInt(x,n)
+{
+  var i,k,c,b;
+  x[0]+=n;
+  k=x.length;
+  c=0;
+  for (i=0;i<k;i++) {
+    c+=x[i];
+    b=0;
+    if (c<0) {
+      alert("c negative ma gayu");
+      b=-(c>>bits_per_element);
+      c+=b*radix;
+    }
+    x[i]=c & mask;
+    c=(c>>bits_per_element)-b;
+    if (!c) return; //stop carrying as soon as the carry is zero
+  }
+}
+
+/*
+ *  To convert the string into the BigInt.
+ *  Pad the array with leading zeros so that it has at least minSize elements.
+ *  The array will always have at least one leading zero, unless base=-1.
+ *
+ *  @param String s input string
+ *  @param  int base base of the output number
+ *  @param  int minSize minimum size of the bigInt
+ *  @return bigInt
+ */
+function str2bigInt(s,base,minSize)
+{
+  var d, i, j, x, y, kk;
+  var digitsStr='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
+  var k=s.length;
+  x=int2bigInt(0,base*k,0);
+   for (i=0;i<k;i++) {
+    d=digitsStr.indexOf(s.substring(i,i+1),0);
+    if (base<=36 && d>=36) {  //convert lowercase to uppercase if base<=36
+      d-=26;
+    }
+    if (d>=base || d<0) {
+      break;
+    }
+    multInt(x,base);
+    addBigIntToInt(x,d);
+  }
+
+  for (k=x.length;k>0 && !x[k-1];k--); //strip off leading zeros
+  k=minSize>k+1 ? minSize : k+1;
+  y=new Array(k);
+  kk=k<x.length ? k : x.length;
+  for (i=0;i<kk;i++)
+    y[i]=x[i];
+  for (;i<k;i++)
+    y[i]=0;
+
+  return y;
+}
+
+/*
+ *  convert a bigInt into a string in a given base, from base 2 up to base 95.
+ *
+ *  @param bigInt x input number
+ *  @param  int base base of the output number
+ *  @return String result
+ */
+function bigInt2str(x,base) {
+  var i,t,s="";
+  var digitsStr='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
+  var temp_array = new Array();
+  if (temp_array.length!=x.length){
+    temp_array=dup(x);
+  } else {
+    copyBigIntToBigInt(temp_array,x);
+  }
+  while (!isZero(temp_array)) {
+      t=divInt_(temp_array,base);  //t=s6 % base; s6=floor(s6/base);
+      s=digitsStr.substring(t,t+1)+s;
+    }
+   if (s.length==0){
+    s="0";
+   }
+  return s;
+}
+
+/*
+ *  To make the copy of the bigInt
+ *
+ *  @param bigInt x input number
+ *  @return bigInt buffer copy of the bigInt x
+ */
+function dup(x) {
+  var i,buff;
+  buff=new Array(x.length);
+  copyBigIntToBigInt(buff,x);
+  return buff;
+}
+
+/*
+ *  To check whether bigInt is zero or not.
+ *  Returns 0 if the bigInt is zero otherwise return 1
+ *  @param bigInt x input number
+ *  @return int
+ */
+function isZero(x) {
+  for (var i=0;i<x.length;i++){
+    if (x[i]) {
+      return 0;
+    }
+  }
+  return 1;
+}
+
+/*
+ *  To do x=floor(x/n) for bigInt x and integer n, and
+ *  @param bigInt x numerator
+ *  @param int n denomenator
+ *  @return int r reminder
+ */
+function divInt_(x,n) {
+  var i,r=0,s;
+  for (var i=x.length-1;i>=0;i--) {
+    s=r*radix+x[i];
+    x[i]=Math.floor(s/n);
+    r=s%n;
+  }
+  return r;
+}
+
+/*
+ *  To do x=x * n. Stores the result in x/
+ *  @param bigInt x  input number
+ *  @param int n input number
+ */
+function multInt(x,n)
+{
+  if (n==0){
+    return;
+  }
+  var i,k,c,b;
+  k=x.length;
+  c=0;
+  for (i=0;i<k;i++) {
+    c+=x[i]*n;
+    b=0;
+    if (c<0) {
+      b=-(c>>bits_per_element);
+      c+=b*radix;
+    }
+    x[i]=c & mask;
+    c=(c>>bits_per_element)-b;
+  }
+}
+
+/*
+ *  Performs x = x * y.
+ *  @param bigInt x  input number
+ *  @param bigInt y  input number
+ *  @return bigInt ans result of multiplication
+ */
+function mult(x,y) {
+
+  var ans=expandBigInt(x,x.length+y.length);
+  mult_(ans,y);
+  return trimBigInt(ans,1);
+}
+
+/*
+ *  Performs x = x * y. Stores the result in x
+ *  @param bigInt x  input number
+ *  @param bigInt y  input number
+ */
+function mult_(x,y) {
+  var result=new Array(2*x.length);
+  copyBigIntToInt(result,0);
+  for (var i=0;i<y.length;i++){
+    if (y[i]){
+      linearCombShift(result,x,y[i],i);
+    }
+  }
+  copyBigIntToBigInt(x,result);
+}
+
+/*
+ *  linear combination x=a*x+b*(y<<(ys*bits_per_element))
+ *  for bigInts x and y, and integers a, b and ys.
+ *  @param bigInt x  to store the result
+ *  @param bigInt y  input number
+ *  @param integer b  single digit of the second number
+ *  @param integer ys  to get bit shift operator
+ */
+function linearCombShift(x,y,b,ys) {
+  var i,c,k,kk;
+  k=x.length<ys+y.length ? x.length : ys+y.length;
+  kk=x.length;
+  for (c=0,i=ys;i<k;i++) {
+    c+=x[i]+b*y[i-ys];
+    x[i]=c & mask;
+    c>>=bits_per_element;
+  }
+  for (i=k;c && i<kk;i++) {
+    c+=x[i];
+    x[i]=c & mask;
+    c>>=bits_per_element;
+  }
+}
+
+/*
+ *  To perform divide operation
+ *  @param bigInt x  Dividend
+ *  @param bigInt y  Divisor
+ *  @param bigInt q  to store the quotient
+ *  @param integer r to store the reminder
+ */
+function divide(x,y,q,r) {
+
+  var kx, ky;
+  var i,j,y1,y2,c,a,b;
+  copyBigIntToBigInt(r,x);
+  for (ky=y.length;y[ky-1]==0;ky--);
+  b=y[ky-1];
+  for (a=0; b; a++)
+  b>>=1;
+  a=bits_per_element-a;
+  leftShift(y,a);
+  leftShift(r,a);
+  for (kx=r.length;r[kx-1]==0 && kx>ky;kx--);
+  copyBigIntToInt(q,0);                      // q=0
+  while (!greaterShift(y,r,kx-ky)) {
+    subShift(r,y,kx-ky);
+    q[kx-ky]++;
+  }
+  for (i=kx-1; i>=ky; i--) {
+      if (r[i]==y[ky-1])
+      {
+      q[i-ky]=mask;
+      alert(5);
+      } else {
+      q[i-ky]=Math.floor((r[i]*radix+r[i-1])/y[ky-1]);
+      }
+      for (;;) {
+      y2=(ky>1 ? y[ky-2] : 0)*q[i-ky];
+      c=y2>>bits_per_element;
+      y2=y2 & mask;
+      y1=c+q[i-ky]*y[ky-1];
+      c=y1>>bits_per_element;
+      y1=y1 & mask;
+      if (c==r[i] ? y1==r[i-1] ? y2>(i>1 ? r[i-2] : 0) : y1>r[i-1] : c>r[i])
+        q[i-ky]--;
+      else
+        break;
+    }
+
+    linearCombShift(r,y,-q[i-ky],i-ky);
+    if (negative(r)) {
+      addShift_(r,y,i-ky);
+      q[i-ky]--;
+    }
+  }
+
+  rightShift(y,a);
+  rightShift(r,a);
+}
+
+/*
+ *  Performs left shift operation on bigInt by given nu,ber of bits
+ *  @param bigInt x  input number
+ *  @param integer n  number of bits to be shifted
+ */
+function leftShift(x,n)
+{
+  var i;
+  var k=Math.floor(n/bits_per_element);
+  if (k) {
+    for (i=x.length; i>=k; i--) //left shift x by k elements
+      x[i]=x[i-k];
+    for (;i>=0;i--)
+      x[i]=0;
+    n%=bits_per_element;
+  }
+  if (!n)
+    return;
+  for (i=x.length-1;i>0;i--) {
+  x[i]=mask & ((x[i]<<n) | (x[i-1]>>(bits_per_element-n)));
+  }
+  x[i]=mask & (x[i]<<n);
+}
+
+
+/*
+ *  Performs right shift operation on bigInt by given nu,ber of bits
+ *  @param bigInt x  input number
+ *  @param integer n  number of bits to be shifted
+ */
+function rightShift(x,n)
+{
+  var i;
+  var k=Math.floor(n/bits_per_element);
+  if (k) {
+    for (i=0;i<x.length-k;i++){ //right shift x by k elements
+      x[i]=x[i+k];
+    }
+    for (;i<x.length;i++){
+      x[i]=0;
+    }
+    n%=bits_per_element;
+  }
+  for (i=0;i<x.length-1;i++) {
+    x[i]=mask & ((x[i+1]<<(bits_per_element-n)) | (x[i]>>n));
+  }
+  x[i]>>=n;
+}
+
+/*
+ *  To check whether BigInt is negative or not
+ *  @return integer output 1 if it is negative otherwise 0
+ */
+function negative(x) {
+  var output = (x[x.length-1]>>(bits_per_element-1))&1;
+  return output;
+}
+
+
+/*
+ *  To perfrom x=x+(y<<(ys*bits_per_element))
+ *  @param bigInt x  first input number
+ *  @param bigInt y  second input number
+ *  @return integer output 1 if it is negative otherwise 0
+ */
+function addShift_(x,y,ys) {
+  var i,c,k,kk;
+  k=x.length<ys+y.length ? x.length : ys+y.length;
+  kk=x.length;
+  for (c=0,i=ys;i<k;i++) {
+    c+=x[i]+y[i-ys];
+    x[i]=c & mask;
+    c>>=bits_per_element;
+  }
+  for (i=k;c && i<kk;i++) {
+    c+=x[i];
+    x[i]=c & mask;
+    c>>=bits_per_element;
+  }
+}
+
+/*
+ *  To check (x << (shift*bpe)) > y.
+ *  @param bigInt x  nonnegative input number
+ *  @param bigInt y  nonnegative input number
+ *  @param integer shift nonnegative integer
+ *  @return integer output 1 if the check passes otherwise returns 0
+ */
+function greaterShift(x,y,shift) {
+  var i, kx=x.length, ky=y.length, k;
+  k=((kx+shift)<ky) ? (kx+shift) : ky;
+  for (i=ky-1-shift; i<kx && i>=0; i++)
+  {
+    if (x[i]>0) {
+      return 1;
+    }
+  }
+  for (i=kx-1+shift; i<ky; i++)
+  {
+    if (y[i]>0) {
+      return 0;
+    }
+  }
+  for (i=k-1; i>=shift; i--)
+  {
+    if (x[i-shift]>y[i]) {
+        return 1;
+    } else if (x[i-shift]<y[i]) {
+        return 0;
+    }
+ }
+  return 0;
+}
+
+
+/*
+ *  To perform x=x-(y<<(ys*bpe)). The result is stored in x.
+ *  @param bigInt x  BigInt number
+ *  @param bigInt y  BigInt number
+ *  @param integer shift number of shift bits
+ */
+function subShift(x,y,ys)
+{
+  var i,c,k,kk;
+  k=x.length<ys+y.length ? x.length : ys+y.length;
+  kk=x.length;
+  for (c=0,i=ys;i<k;i++) {
+    c+=x[i]-y[i-ys];
+    x[i]=c & mask;
+    c>>=bits_per_element;
+  }
+  for (i=k;c && i<kk;i++) {
+    c+=x[i];
+    x[i]=c & mask;
+    c>>=bits_per_element;
+  }
+}
+
+/*
+ *  Wrapper method for the mod operation
+ *  @param bigInt x  BigInt number
+ *  @param integer n  number
+ *  @return result result=x mod n
+ */
+function mod(x,n)
+{
+  var ans=dup(x);
+  modCalculation(ans,n);
+  var result = trim(ans,1);
+  return result;
+}
+
+/*
+ *  To perform result= x mod n.
+ *  @param bigInt x  BigInt number
+ *  @param integer n  number
+ *  @return result result=x mod n
+ */
+function modCalculation(x,n)
+{
+  var s4=new Array(0);
+  var s5=new Array(0);
+  if (s4.length!=x.length)
+    s4=dup(x);
+  else
+    copyBigIntToBigInt(s4,x);
+  if (s5.length!=x.length)
+    s5=dup(x);
+  divide(s4,n,s5,x);
+}
+
+/*
+ *  To return x with exactly k leading zeroes
+ *  @param bigInt x  BigInt number
+ *  @param integer k  expected number of leading zeroes in x
+ *  @return result result=x mod n
+ */
+function trim(x,k) {
+  var i,y;
+  for (i=x.length; i>0 && !x[i-1]; i--);
+  y=new Array(i+k);
+  copyBigIntToBigInt(y,x);
+  return y;
+}
+
+/*
+ *  Wrapper method for performing multplication modular opearion
+ *  @param bigInt x  BigInt number
+ *  @param bigInt y  BigInt number
+ *  @param bigInt n  modulus
+ *  @return bigInt x*y mod n
+ */
+function multMod(x,y,n) {
+  var ans=expand(x,n.length);
+  multModOperation(ans,y,n);
+  return trim(ans,1);
+}
+
+/*
+ *  To perform multplication modular opearion
+ *  @param bigInt x  BigInt number
+ *  @param bigInt y  BigInt number
+ *  @param bigInt n  modulus
+ *  @return bigInt x*y mod n
+ */
+ function multModOperation(x,y,n)
+ {
+  var s0=new Array(2*x.length);
+  copyBigIntToInt(s0,0);
+  for (var i=0;i<y.length;i++){
+    if (y[i]){
+      linearCombShift(s0,x,y[i],i);
+    }
+  }
+  modCalculation(s0,n);
+  copyBigIntToBigInt(x,s0);
+}
+
+/*
+ *  To expand bigInt for the given number of elements.
+ *  Leadin zeros are added
+ *  @param bigInt x  BigInt number
+ *  @param integer n  expected number of elements
+ *  @return ans x*y mod n
+ */
+function expand(x,n) {
+  var ans=int2bigInt(0,(x.length>n ? x.length : n)*bits_per_element,0);
+  copyBigIntToBigInt(ans,x);
+  return ans;
+}
\ No newline at end of file
diff --git a/scripts/hashcaptcha.js b/scripts/hashcaptcha.js
index 620dc24..0bb99bb 100644
--- a/scripts/hashcaptcha.js
+++ b/scripts/hashcaptcha.js
@@ -72,205 +72,4 @@ function hashStamp(random_string, time, level)
         input_string = random_string +':'+time + ':' + nonce;
     }
     return nonce;
-}
-
-/*
- *  To calculate the sha1 on the given String.
- *
- *  @param String input string for the function
- *  @return String sha1 of the input string
- */
-function generateSha1(str)
-{
-    var n = ((str.toString().length + 8) >> 6) + 1;
-    var x = new Array();
-
-    for (var i = 0; i < n * 16; i++) {
-        x[i] = 0;
-    }
-
-    for (i = 0; i < str.toString().length; i++) {
-        x[i >> 2] +=
-            (str.toString().substr(i, 1)).charCodeAt(0) << (24 - (i % 4) * 8);
-    }
-
-    x[i >> 2] |= 0x80 << (24 - (i % 4) * 8);
-    x[n * 16 - 1] = str.toString().length * 8;
-
-    var a = 1732584193;
-    var b = -271733879;
-    var c = -1732584194;
-    var d = 271733878;
-    var e = -1009589776;
-
-    var w = new Array();
-
-    for (i = 0; i < x.length; i += 16) {
-        var olda = a;
-        var oldb = b;
-        var oldc = c;
-        var oldd = d;
-        var olde = e;
-
-        for (var j = 0; j < 80; j++) {
-            if (j < 16) {
-                w[j] = x[i + j];
-            } else {
-                w[j] = rotate(w[j - 3]^w[j - 8]^w[j - 14]^w[j - 16], 1);
-            }
-            var t = safeAdd(safeAdd(rotate(a, 5),
-                    hashOperationByIteration(j, b, c, d)),
-                    safeAdd(safeAdd(e, w[j]), constantForIteration(j)));
-            e = d;
-            d = c;
-            c = rotate(b, 30);
-            b = a;
-            a = t;
-        }
-
-        a = safeAdd(a, olda);
-        b = safeAdd(b, oldb);
-        c = safeAdd(c, oldc);
-        d = safeAdd(d, oldd);
-        e = safeAdd(e, olde);
-    }
-    return bin2hex(Array(a, b, c, d, e));
-}
-
-/*
- *  To conver a binary array into a hexadecimal value
- *
- *  @param array binarray array of a 5 binary values
- *  @return String hexadecimal
- */
-function bin2hex(binarray)
-{
-    var hex_case = 0;
-    var hex_tab = hex_case ? "0123456789ABCDEF" : "0123456789abcdef";
-    var str = "";
-    for (var i = 0; i < binarray.length * 4; i++) {
-        str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4))
-        & 0xF)+hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8))
-        & 0xF);
-    }
-    return str;
-}
-
-/*
- *  Calculate the one of the operand of a safe_add function
- *  based on the iteration value
- *
- *  @param int t value of iteration
- *  @param int b constant value
- *  @param int c constant value
- *  @param int d constant value
- *  @return int result of a xor value on constants
- */
-function hashOperationByIteration(t, b, c, d)
-{
-    if (t < 20) {
-        return (b & c) | ((~b) & d);
-    }
-    if (t < 40) {
-        return b^c^d;
-    }
-    if (t < 60) {
-        return (b & c) | (b & d) | (c & d);
-    }
-    return b^c^d;
-}
-
-/*
- *  To find a constant based on the iteration
- *
- *  @param int t value of iteration
- *  @return int constant value
- */
-function constantForIteration(t)
-{
-    if (t < 20) {
-        return 1518500249;
-    } else if (t < 40) {
-        return 1859775393;
-    } else if (t < 60) {
-        return -1894007588;
-    } else {
-        return -899497514;
-    }
-}
-
-/*
- *  To add integers, wrapping at 2^32
- *
- *  @param int x first operand of the add operation
- *  @param int y second operand of the add operation
- *  @return int result of the add operation
- */
-function safeAdd(x, y)
-{
-    var lsw = (x & 0xFFFF) + (y & 0xFFFF);
-    var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
-    return (msw << 16) | (lsw & 0xFFFF);
-}
-
-/*
- *  Bitwise rotate a 32-bit number
- *
- *  @param int num number on which rotation operation is performed
- *  @param int count define a number of times the shift opeation should perform
- *  @return int result of the rotate operation
- */
-function rotate(num, cnt)
-{
-    return (num << cnt) | zeroFill(num, 32 - cnt);
-}
-
-/*
- *  Use for a zero padding to the input number if a number is not 32 bit
- *
- *  @param int a input number
- *  @param int b to define how many leading zero should be added
- *  @return int 32 bit number
- */
-function zeroFill(a, b)
-{
-    var bin = dec2bin(a);
-
-    if (bin.toString().length < b) {
-        bin = 0;
-    } else {
-        var length = bin.toString().length;
-        bin = bin.toString().substr(0, length - b);
-    }
-
-    for (var i = 0; i < b; i++) {
-        bin = "0" + bin;
-    }
-    return bin2dec(bin);
-}
-
-/*
- *  Convert decimal number to binary string
- *
- *  @param int number input number
- *  @return string binary number
- */
-function dec2bin(number)
-{
-    if (number < 0) {
-        number = 0xFFFFFFFF + number + 1;
-    }
-    return parseInt(number, 10).toString(2);
-}
-
-/*
- *  Convert binary string to decimal number
- *
- *  @param string binary string input string
- *  @return int decimal number
- */
-function bin2dec(binary_string)
-{
-    binary_string = (binary_string + '').replace(/[^01]/gi, '');
-    return parseInt(binary_string, 2);
 }
\ No newline at end of file
diff --git a/scripts/mix.js b/scripts/mix.js
index 28e61ae..013c20e 100644
--- a/scripts/mix.js
+++ b/scripts/mix.js
@@ -316,4 +316,4 @@ function drawNumResultSelect(i, selected_num) {
     }
     select += "</select>";
     return select;
-}
+}
\ No newline at end of file
diff --git a/scripts/sha1.js b/scripts/sha1.js
new file mode 100644
index 0000000..fcb4f4e
--- /dev/null
+++ b/scripts/sha1.js
@@ -0,0 +1,231 @@
+/**
+ *  SeekQuarry/Yioop --
+ *  Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ *  Copyright (C) 2009 - 2014  Chris Pollett chris@pollett.org
+ *
+ *  LICENSE:
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  END LICENSE
+ *
+ * @author Chris Pollett chris@pollett.org
+ * @package seek_quarry
+ * @subpackage javascript
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2009 - 2014
+ * @filesource
+ */
+
+ /*
+ *  To calculate the sha1 on the given String.
+ *
+ *  @param String input string for the function
+ *  @return String sha1 of the input string
+ */
+function generateSha1(str)
+{
+    var n = ((str.toString().length + 8) >> 6) + 1;
+    var x = new Array();
+
+    for (var i = 0; i < n * 16; i++) {
+        x[i] = 0;
+    }
+
+    for (i = 0; i < str.toString().length; i++) {
+        x[i >> 2] +=
+            (str.toString().substr(i, 1)).charCodeAt(0) << (24 - (i % 4) * 8);
+    }
+
+    x[i >> 2] |= 0x80 << (24 - (i % 4) * 8);
+    x[n * 16 - 1] = str.toString().length * 8;
+
+    var a = 1732584193;
+    var b = -271733879;
+    var c = -1732584194;
+    var d = 271733878;
+    var e = -1009589776;
+
+    var w = new Array();
+
+    for (i = 0; i < x.length; i += 16) {
+        var olda = a;
+        var oldb = b;
+        var oldc = c;
+        var oldd = d;
+        var olde = e;
+
+        for (var j = 0; j < 80; j++) {
+            if (j < 16) {
+                w[j] = x[i + j];
+            } else {
+                w[j] = rotate(w[j - 3]^w[j - 8]^w[j - 14]^w[j - 16], 1);
+            }
+            var t = safeAdd(safeAdd(rotate(a, 5),
+                    hashOperationByIteration(j, b, c, d)),
+                    safeAdd(safeAdd(e, w[j]), constantForIteration(j)));
+            e = d;
+            d = c;
+            c = rotate(b, 30);
+            b = a;
+            a = t;
+        }
+        a = safeAdd(a, olda);
+        b = safeAdd(b, oldb);
+        c = safeAdd(c, oldc);
+        d = safeAdd(d, oldd);
+        e = safeAdd(e, olde);
+    }
+    return bin2hex(Array(a, b, c, d, e));
+}
+
+/*
+ *  To conver a binary array into a hexadecimal value
+ *
+ *  @param array binarray array of a 5 binary values
+ *  @return String hexadecimal
+ */
+function bin2hex(binarray)
+{
+    var hex_case = 0;
+    var hex_tab = hex_case ? "0123456789ABCDEF" : "0123456789abcdef";
+    var str = "";
+    for (var i = 0; i < binarray.length * 4; i++) {
+        str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4))
+        & 0xF)+hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8))
+        & 0xF);
+    }
+    return str;
+}
+
+/*
+ *  Calculate the one of the operand of a safe_add function
+ *  based on the iteration value
+ *
+ *  @param int t value of iteration
+ *  @param int b constant value
+ *  @param int c constant value
+ *  @param int d constant value
+ *  @return int result of a xor value on constants
+ */
+function hashOperationByIteration(t, b, c, d)
+{
+    if (t < 20) {
+        return (b & c) | ((~b) & d);
+    }
+    if (t < 40) {
+        return b^c^d;
+    }
+    if (t < 60) {
+        return (b & c) | (b & d) | (c & d);
+    }
+    return b^c^d;
+}
+
+/*
+ *  To find a constant based on the iteration
+ *
+ *  @param int t value of iteration
+ *  @return int constant value
+ */
+function constantForIteration(t)
+{
+    if (t < 20) {
+        return 1518500249;
+    } else if (t < 40) {
+        return 1859775393;
+    } else if (t < 60) {
+        return -1894007588;
+    } else {
+        return -899497514;
+    }
+}
+
+/*
+ *  To add integers, wrapping at 2^32
+ *
+ *  @param int x first operand of the add operation
+ *  @param int y second operand of the add operation
+ *  @return int result of the add operation
+ */
+function safeAdd(x, y)
+{
+    var lsw = (x & 0xFFFF) + (y & 0xFFFF);
+    var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
+    return (msw << 16) | (lsw & 0xFFFF);
+}
+
+/*
+ *  Bitwise rotate a 32-bit number
+ *
+ *  @param int num number on which rotation operation is performed
+ *  @param int count define a number of times the shift opeation should perform
+ *  @return int result of the rotate operation
+ */
+function rotate(num, cnt)
+{
+    return (num << cnt) | zeroFill(num, 32 - cnt);
+}
+
+/*
+ *  Use for a zero padding to the input number if a number is not 32 bit
+ *
+ *  @param int a input number
+ *  @param int b to define how many leading zero should be added
+ *  @return int 32 bit number
+ */
+function zeroFill(a, b)
+{
+    var bin = dec2bin(a);
+
+    if (bin.toString().length < b) {
+        bin = 0;
+    } else {
+        var length = bin.toString().length;
+        bin = bin.toString().substr(0, length - b);
+    }
+
+    for (var i = 0; i < b; i++) {
+        bin = "0" + bin;
+    }
+    return bin2dec(bin);
+}
+
+/*
+ *  Convert decimal number to binary string
+ *
+ *  @param int number input number
+ *  @return string binary number
+ */
+function dec2bin(number)
+{
+    if (number < 0) {
+        number = 0xFFFFFFFF + number + 1;
+    }
+    return parseInt(number, 10).toString(2);
+}
+
+/*
+ *  Convert binary string to decimal number
+ *
+ *  @param string binary string input string
+ *  @return int decimal number
+ */
+function bin2dec(binary_string)
+{
+    binary_string = (binary_string + '').replace(/[^01]/gi, '');
+    return parseInt(binary_string, 2);
+}
\ No newline at end of file
diff --git a/scripts/zkp.js b/scripts/zkp.js
new file mode 100644
index 0000000..1ca40a2
--- /dev/null
+++ b/scripts/zkp.js
@@ -0,0 +1,210 @@
+/**
+ *  SeekQuarry/Yioop --
+ *  Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ *  Copyright (C) 2009 - 2014  Chris Pollett chris@pollett.org
+ *
+ *  LICENSE:
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  END LICENSE
+ *
+ * @author Chris Pollett chris@pollett.org
+ * @package seek_quarry
+ * @subpackage javascript
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2009 - 2014
+ * @filesource
+ */
+
+/*
+ *  To set the user_name and passsword in the cookies. This cookie is used in the
+ *  zero knowldge authentication module
+ *
+ *  @param String cname name of the cookie. user_name is used as cname
+ *  @param String cvalue value of the cookie. Password is used as cvalue
+ *  @param int exdays expiration time for the cookie
+ */
+function setCookie(cname, cvalue, exdays)
+{
+    var date = new Date();
+    date.setTime(date.getTime() + (exdays * 1000 * 60 * 2));
+    var expires = "expires=" + date.toGMTString();
+    document.cookie = cname + "=" + cvalue + "; " + expires;
+}
+
+/*
+ *  To get the passsword from the cookies. This cookie is used in the
+ *  zero knowldge authentication module
+ *
+ *  @param String cname name of the cookie. user_name is used as cname
+ *  @return String c cookie associated with the cookie name
+ */
+function getCookie(cname)
+{
+    var name = cname + "=";
+    var ca = document.cookie.split(';');
+    for (var i = 0; i < ca.length; i++) {
+        var c = ca[i].trim();
+        if (c.indexOf(name) == 0)
+            return c.substring(name.length, c.length);
+    }
+    return "";
+}
+
+/*
+ *  Returns RSA like modulus.
+ *
+ *  @return BigInteger RSA like modulus.
+ */
+
+function getN()
+{
+    var n = "49118961436116337806824024538499898007751892042"+
+    "5206572640822072909366693516929533335497211595856159654188292674113817"+
+    "4142872698595829944178957090296779606642580976458630868510407440881709"+
+    "556568052691";
+    return str2bigInt(n, 10,0);
+}
+
+/*
+ *  Generates Fiat shamir parameters such as x and y and append
+ *  with the input form
+ *
+ *  @param Object form1 id of the form
+ *  @param int e random value sent by the server. Either 0 or 1.
+ *  @param String user_name id of the form
+ */
+function dynamicForm(form1, e, user_name)
+{
+    var theForm,newInput1,newInput2;
+    theForm = elt(form1);
+    var n = getN();
+    var r = getR();
+    var x = multMod(r,r,n);
+    var y = getY('', e, r, n);
+    newInput1 = ce('input');
+    newInput1.type = 'hidden';
+    newInput1.name = 'x1';
+    newInput1.value = bigInt2str(x,10);
+    newInput2 = ce('input');
+    newInput2.type = 'hidden';
+    newInput2.name = 'y1';
+    newInput2.value = bigInt2str(y,10);
+    newInput3 = ce('input');
+    newInput3.type = 'hidden';
+    newInput3.name = 'u';
+    newInput3.value = user_name;
+
+    theForm.appendChild(newInput1);
+    theForm.appendChild(newInput2);
+    theForm.appendChild(newInput3);
+    elt('hidden_form_container').appendChild(theForm);
+    theForm.submit();
+}
+
+/*
+ *  Generates Fiat shamir parameters Y. When user gives username, password
+ *  for the first time it stored the password on the cookie. From rest of
+ *  the Fiat shamir iteration it uses password stores on the client side
+ *  cookie.
+ *
+ *  @param String sha1 sha1 of the password
+ *  @param int e random value sent by the server. Either 0 or 1.
+ *  @param BigInteger r random value picked by the client
+ *  @param BigInteger n RSA like modulus
+ *  @return BigInteger y fiat-shamir parameter Y.
+ */
+function getY(sha1, e, r, n)
+{
+    if (sha1 == '') {
+        sha1 = getCookie("user_name");
+    } else {
+        setCookie("user_name", sha1, 1);
+    }
+    var s = str2bigInt(sha1,16,0);
+    var se;
+    if(e==0){
+        se = 1;
+        se = se + '';
+        se = str2bigInt(se,10,0);
+    } else {
+        se = s;
+    }
+    y = multMod(r,se,n);
+    return y;
+}
+
+/*
+ *  Generates random number and convert into BigInteger.
+ *  @return BigInteger final_r random BigInteger
+ */
+function getR()
+{
+    var r = Math.floor((Math.random() * 21474) + 1);
+    r = r + '';
+    var final_r = str2bigInt(r,10,0);
+    return final_r;
+}
+
+/*
+ *  Generates Fiat shamir parameters such as x and y and append
+ *  with the input form. This method calls first time when user
+ *  provides user name and password
+ *
+ *  @param Object form1 id of the form
+ *  @param String password1 password provided by user
+ *  @param int e1 random value send by the server. Either 0 or 1.
+ */
+function generateKeys(form1, password1, e)
+{
+    var form = document.getElementById(form1);
+    var password = document.getElementById(password1).value;
+    var n = new getN();
+    var r = getR();
+    var x = multMod(r,r,n);
+    var sha1 = generateSha1(password);
+    var y = getY(sha1, e, r, n);
+    newInput1 = document.createElement('input');
+    newInput1.type = 'hidden';
+    newInput1.name = 'x1';
+    newInput1.value = bigInt2str(x,10);
+    newInput2 = document.createElement('input');
+    newInput2.type = 'hidden';
+    newInput2.name = 'y1';
+    newInput2.value = bigInt2str(y,10);
+    form.appendChild(newInput1);
+    form.appendChild(newInput2);
+}
+
+/*
+ *  This function is used during create account module and when
+ *  authentication mode is ZKP.
+ *
+ *  @param String password password provided by user
+ *  @param String repassword repassword provided by user
+ */
+function registration(password, repassword)
+{
+    var password1 = document.getElementById(password);
+    var repassword1 = document.getElementById(repassword);
+    var sha1 = generateSha1(password1.value);
+    var x = str2bigInt(sha1,16,0);
+    var n = getN();
+    var z = multMod(x,x,n);
+    password1.value = bigInt2str(z,10);
+    repassword1.value = bigInt2str(z,10);
+}
\ No newline at end of file
diff --git a/tests/sha1_test.php b/tests/sha1_test.php
index 8b8136c..39faf85 100644
--- a/tests/sha1_test.php
+++ b/tests/sha1_test.php
@@ -66,7 +66,7 @@ class Sha1Test extends JavaScriptTest
         <div id="sha1Test">
         </div>
         <head>
-        <script type="text/javascript" src="../scripts/hashcaptcha.js" ></script>
+        <script type="text/javascript" src="../scripts/sha1.js" ></script>
         <script type="text/javascript">
         var input_array = <?php echo $js_array; ?>;
         var total_test_cases = <?php echo self::NUM_TEST_CASES?>;
diff --git a/views/crawlstatus_view.php b/views/crawlstatus_view.php
index e1aac40..da7d5a2 100755
--- a/views/crawlstatus_view.php
+++ b/views/crawlstatus_view.php
@@ -264,4 +264,4 @@ class CrawlstatusView extends View
     <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/elements/editmix_element.php b/views/elements/editmix_element.php
index 9334642..b5849ac 100644
--- a/views/elements/editmix_element.php
+++ b/views/elements/editmix_element.php
@@ -95,4 +95,4 @@ class EditmixElement extends Element
     <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/elements/groupfeed_element.php b/views/elements/groupfeed_element.php
index a9ecdbe..461d438 100644
--- a/views/elements/groupfeed_element.php
+++ b/views/elements/groupfeed_element.php
@@ -340,4 +340,4 @@ class GroupfeedElement extends Element implements CrawlConstants
         }
     }
 }
- ?>
+ ?>
\ No newline at end of file
diff --git a/views/elements/manageaccount_element.php b/views/elements/manageaccount_element.php
index 5417461..7f5b43b 100755
--- a/views/elements/manageaccount_element.php
+++ b/views/elements/manageaccount_element.php
@@ -193,4 +193,4 @@ class ManageaccountElement extends Element
         <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/elements/manageclassifiers_element.php b/views/elements/manageclassifiers_element.php
index 85a6bc4..7b60a40 100644
--- a/views/elements/manageclassifiers_element.php
+++ b/views/elements/manageclassifiers_element.php
@@ -72,7 +72,7 @@ class ManageclassifiersElement extends Element
                 e(tl('manageclassifiers_create_button')) ?></button>
         </div>
         </form>
-        <?php if (!empty($data['classifiers'])) { 
+        <?php if (!empty($data['classifiers'])) {
         $data['TABLE_TITLE'] = tl('manageclassifiers_available_classifiers');
         $data['ACTIVITY'] = 'manageClassifiers';
         $data['VIEW'] = $this->view;
@@ -143,4 +143,4 @@ class ManageclassifiersElement extends Element
     <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/elements/managecrawls_element.php b/views/elements/managecrawls_element.php
index 8479083..233e186 100755
--- a/views/elements/managecrawls_element.php
+++ b/views/elements/managecrawls_element.php
@@ -112,4 +112,4 @@ class ManagecrawlsElement
     <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/elements/managegroups_element.php b/views/elements/managegroups_element.php
index 9b4a4ef..2be1a30 100755
--- a/views/elements/managegroups_element.php
+++ b/views/elements/managegroups_element.php
@@ -190,7 +190,7 @@ class ManagegroupsElement extends Element
                 <td><?php
                     if($group['OWNER_ID']!=$_SESSION['USER_ID']||
                         $group['GROUP_NAME'] == 'Public') {
-                        if(isset($group['STATUS']) && 
+                        if(isset($group['STATUS']) &&
                             $group['STATUS'] == INVITED_STATUS) {
                             ?><a href="<?php e($join_url . 'group_id='.
                                 $group['GROUP_ID'].'&amp;user_id=' .
@@ -210,7 +210,7 @@ class ManagegroupsElement extends Element
                     if($group['GROUP_NAME'] == 'Public') {
                         e('<span class="gray">'.
                             tl('managegroups_element_delete').'</span>');
-                    } else if(isset($data['browse']) && 
+                    } else if(isset($data['browse']) &&
                         $data['browse'] == 'true') {
                         if( $group['REGISTER_TYPE'] == NO_JOIN &&
                             $_SESSION['USER_ID']  != ROOT_ID) {
@@ -300,12 +300,12 @@ class ManagegroupsElement extends Element
                 }
                 ?> /></td><?php
                 if($addgroup) { ?>
-                    <td>[<a href="<?php e($browse_url); ?>"><?php 
+                    <td>[<a href="<?php e($browse_url); ?>"><?php
                         e(tl('managegroups_element_browse')); ?></a>]</td>
                 <?php
                 }
         ?></tr>
-        <?php 
+        <?php
         if($creategroup || $editgroup) { ?>
             <tr><th class="table-label"><label for="register-type"><?php
                 e(tl('managegroups_element_register'))?></label>:</th>
@@ -412,7 +412,7 @@ class ManagegroupsElement extends Element
                             </td>
                             <td colspan="2" class="center">
                                 <input class="very-narrow-field center"
-                                    name="user_filter" type="text" 
+                                    name="user_filter" type="text"
                                     max-length="10" value='<?php
                                     e($data['USER_FILTER']); ?>' /><br />
                                 <button type="submit" name="change_filter"
@@ -715,4 +715,4 @@ class ManagegroupsElement extends Element
         <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/elements/manageusers_element.php b/views/elements/manageusers_element.php
index af419ed..7c3e8a2 100644
--- a/views/elements/manageusers_element.php
+++ b/views/elements/manageusers_element.php
@@ -286,7 +286,7 @@ class ManageusersElement extends Element
                     if($data['ROLE_FILTER'] != "" ||
                         (isset($data['NUM_USER_ROLES']) &&
                         $data['NUM_USER_ROLES'] > NUM_RESULTS_PER_PAGE)) {
-                        $limit = isset($data['ROLE_LIMIT']) ? 
+                        $limit = isset($data['ROLE_LIMIT']) ?
                             $data['ROLE_LIMIT']: 0;
                     ?>
                         <div class="center">
@@ -302,7 +302,7 @@ class ManageusersElement extends Element
                                 >&lt;&lt;</a><?php
                             }
                             ?>
-                        <input class="very-narrow-field center" 
+                        <input class="very-narrow-field center"
                             name="role_filter" type="text" max-length="10"
                             value='<?php e($data['ROLE_FILTER']); ?>' />
                             <?php
@@ -368,7 +368,7 @@ class ManageusersElement extends Element
                     if($data['GROUP_FILTER'] != "" ||
                         (isset($data['NUM_USER_GROUPS']) &&
                         $data['NUM_USER_GROUPS'] > NUM_RESULTS_PER_PAGE)) {
-                        $limit = isset($data['GROUP_LIMIT']) ? 
+                        $limit = isset($data['GROUP_LIMIT']) ?
                             $data['GROUP_LIMIT']: 0;
                     ?>
                         <div class="center">
@@ -384,22 +384,22 @@ class ManageusersElement extends Element
                                 >&lt;&lt;</a><?php
                             }
                             ?>
-                        <input class="very-narrow-field center" 
-                            name="group_filter" type="text" max-length="10" 
+                        <input class="very-narrow-field center"
+                            name="group_filter" type="text" max-length="10"
                             value='<?php  e($data['GROUP_FILTER']); ?>' />
                         <?php
                             if($data['NUM_USER_GROUPS'] > $limit +
                                 NUM_RESULTS_PER_PAGE) {
                                 ?><a href='<?php e(
                                 "$action_url&amp;arg=edituser&amp;group_limit=".
-                                ($limit + NUM_RESULTS_PER_PAGE)); 
+                                ($limit + NUM_RESULTS_PER_PAGE));
                                 ?>'>&gt;&gt;</a>
                             <?php
                             }
                         ?><br />
                         <button type="submit" name="change_filter"
                             value="group"><?php
-                        e(tl('manageusers_element_filter')); 
+                        e(tl('manageusers_element_filter'));
                         ?></button><br />&nbsp;
                     </div>
                     <?php
@@ -411,7 +411,7 @@ class ManageusersElement extends Element
                     <button type="submit"
                         class="button-box">
                         <label for='select-group'><?php
-                        e(tl('manageusers_element_add_group')); 
+                        e(tl('manageusers_element_add_group'));
                         ?></label></button>
                     </div>
                     </div>
@@ -602,4 +602,4 @@ class ManageusersElement extends Element
         <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/elements/mixcrawls_element.php b/views/elements/mixcrawls_element.php
index 61c52e7..f3ead51 100644
--- a/views/elements/mixcrawls_element.php
+++ b/views/elements/mixcrawls_element.php
@@ -65,7 +65,7 @@ class MixcrawlsElement extends Element
         } else {
             $this->renderMixForm($data);
         }
-        if($mixes_exist) { 
+        if($mixes_exist) {
         $data['TABLE_TITLE'] = tl('mixcrawls_element_available_mixes');
         $data['ACTIVITY'] = 'mixCrawls';
         $data['VIEW'] = $this->view;
@@ -250,4 +250,4 @@ class MixcrawlsElement extends Element
         <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/elements/serversettings_element.php b/views/elements/serversettings_element.php
index 2d4bb08..d3c2742 100644
--- a/views/elements/serversettings_element.php
+++ b/views/elements/serversettings_element.php
@@ -251,6 +251,20 @@ class ServersettingsElement extends Element
                 ?>
             </fieldset>
             </div>
+            <div class="top-margin">
+            <fieldset>
+                <legend><label
+                for="authentication-mode"><?php
+                e(tl('serversettings_element_authentication_mode'));
+                ?>
+                </label></legend>
+                    <?php $this->view->helper("options")->render(
+                        "authentication-mode", "AUTHENTICATION_MODE",
+                       $data['AUTHENTICATION_MODES'],
+                     $data['AUTHENTICATION_MODE']);
+                ?>
+            </fieldset>
+            </div>
             <div class="top-margin center">
             <button class="button-box" type="submit"><?php
                 e(tl('serversettings_element_submit')); ?></button>
@@ -262,4 +276,4 @@ class ServersettingsElement extends Element
     <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/elements/signin_element.php b/views/elements/signin_element.php
index 2b136b5..c78b377 100755
--- a/views/elements/signin_element.php
+++ b/views/elements/signin_element.php
@@ -84,4 +84,4 @@ class SigninElement extends Element
     <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/helpers/feeds_helper.php b/views/helpers/feeds_helper.php
index 7523629..7d352b8 100644
--- a/views/helpers/feeds_helper.php
+++ b/views/helpers/feeds_helper.php
@@ -175,4 +175,4 @@ class FeedsHelper extends Helper implements CrawlConstants
         return $pub_date;
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/helpers/pagingtable_helper.php b/views/helpers/pagingtable_helper.php
index df2b101..5b636b5 100644
--- a/views/helpers/pagingtable_helper.php
+++ b/views/helpers/pagingtable_helper.php
@@ -221,4 +221,4 @@ class PagingtableHelper extends Helper
         }
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/layouts/web_layout.php b/views/layouts/web_layout.php
index 74d79e3..aaa0157 100755
--- a/views/layouts/web_layout.php
+++ b/views/layouts/web_layout.php
@@ -152,4 +152,4 @@ class WebLayout extends Layout
     </html><?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/recover_view.php b/views/recover_view.php
index 57fe7e6..01bd558 100644
--- a/views/recover_view.php
+++ b/views/recover_view.php
@@ -78,7 +78,19 @@ class RecoverView extends View
             <form method="post" action="#">
             <input type="hidden" name="c" value="register" />
             <input type="hidden" name="a" value="<?php e($activity); ?>" />
+             <?php if(isset($_SESSION["random_string"])) { ?>
+            <input type='hidden' name='nonce_for_string'
+            id='nonce_for_string' />
+            <input type='hidden' name='random_string' id='random_string'
+                value='<?php e($_SESSION["random_string"]);?>' />
+            <input type='hidden' name='time1' id='time1'
+                value='<?php e($_SESSION["request_time"]);?>' />
+            <input type='hidden' name='level' id='level'
+                value='<?php e($_SESSION["level"]);?>' />
+            <input type='hidden' name='time' id='time'
+                value='<?php e(time());?>'/>
             <?php
+            }
             if(isset($data["RECOVER_COMPLETE"])) { ?>
                 <input type="hidden" name="user" value="<?php
                     e($data['user']); ?>" />
@@ -139,32 +151,39 @@ class RecoverView extends View
                             tl('register_view_account_recovery')
                                 =>$data['RECOVERY']);
                     } else {
-                        $question_sets = array(
-                            tl('register_view_human_check')=>$data['CAPTCHAS']);
+                        if(isset($_SESSION["random_string"])) {
+                            $question_sets = array();
+                        } else {
+                            $question_sets = array(
+                                tl('register_view_human_check')=>
+                                $data['CAPTCHAS']);
+                        }
                     }
-                    $i = 0;
-                    foreach($question_sets as $name => $set) {
-                        $first = true;
-                        $num = count($set);
-                        foreach($set as $question) {
-                            if($first) { ?>
-                                <tr><th class="table-label"
-                                    rowspan='<?php e($num); ?>'><?php
-                                    e($name);
-                                ?></th><td class="table-input border-top">
-                            <?php
-                            } else { ?>
-                                <tr><td class="table-input">
-                            <?php
+                    if(isset($_SESSION["random_string"])) {
+                        $i = 0;
+                        foreach($question_sets as $name => $set) {
+                            $first = true;
+                            $num = count($set);
+                            foreach($set as $question) {
+                                if($first) { ?>
+                                    <tr><th class="table-label"
+                                        rowspan='<?php e($num); ?>'><?php
+                                        e($name);
+                                    ?></th><td class="table-input border-top">
+                                <?php
+                                } else { ?>
+                                    <tr><td class="table-input">
+                                <?php
+                                }
+                                $this->helper("options")->render(
+                                    "question-$i", "question_$i",
+                                    $question, $data["question_$i"]);
+                                $first = false;
+                                e(in_array("question_$i", $missing)
+                                    ?'<span class="red">*</span>':'');
+                                e("</td></tr>");
+                                $i++;
                             }
-                            $this->helper("options")->render(
-                                "question-$i", "question_$i",
-                                $question, $data["question_$i"]);
-                            $first = false;
-                            e(in_array("question_$i", $missing)
-                                ?'<span class="red">*</span>':'');
-                            e("</td></tr>");
-                            $i++;
                         }
                     }
                     ?>
@@ -191,6 +210,15 @@ class RecoverView extends View
         </div>
         </div>
         <div class='tall-landing-spacer'></div>
+        <?php  if(isset($_SESSION["random_string"])) {?>
+        <script type="text/javascript" >
+            document.addEventListener('DOMContentLoaded', function() {
+            var body = tag(body);
+            body.onload = findNonce('nonce_for_string', 'random_string'
+                , 'time', 'level');
+            }, false);
+        </script>
         <?php
+        }
     }
 }
\ No newline at end of file
diff --git a/views/register_view.php b/views/register_view.php
index 782491a..f8cc86b 100755
--- a/views/register_view.php
+++ b/views/register_view.php
@@ -73,6 +73,15 @@ class RegisterView extends View
                 src="<?php e($logo); ?>" alt="Yioop!"/></a>
                 <span> - <?php e(tl('register_view_create_account'));
                 ?></span></h1>
+               <?php if($data['AUTHENTICATION_MODE'] == 'zkp_authentication')
+                  { ?>
+                        <form action="" method="post" onsubmit="registration('password','repassword')">
+                        <input type="hidden" name="numericPassword" id="numericPassword"/>
+                  <?php }
+                  else
+                  { ?>
+                        <form method="post" action="#">
+            <?php }?>
             <form method="post" action="#">
             <input type="hidden" name="c" value="register" />
             <input type="hidden" name="a" value="processAccountData" />
@@ -150,8 +159,7 @@ class RegisterView extends View
                             <td class="table-input">
                                 <input id="password" type="password"
                                     class="narrow-field" maxlength="80"
-                                    name="password" value="<?php
-                                    e($data['PASSWORD']); ?>" />
+                                    name="password" />
                                 <?php echo in_array("password", $missing)
                                     ? '<span class="red">*</span>':'';?></td>
                         </tr>
@@ -164,8 +172,7 @@ class RegisterView extends View
                             <td class="table-input">
                                 <input id="repassword" type="password"
                                     class="narrow-field" maxlength="80"
-                                    name="repassword" value="<?php
-                                    e($data['REPASSWORD']); ?>" />
+                                    name="repassword"  />
                                 <?php echo in_array("repassword", $missing)
                                     ?'<span class="red">*</span>':''; ?></td>
                         </tr>
@@ -243,4 +250,4 @@ class RegisterView extends View
     <?php
         }
     }
-    ?>
+    ?>
\ No newline at end of file
diff --git a/views/settings_view.php b/views/settings_view.php
index fdbd4c9..ff24159 100755
--- a/views/settings_view.php
+++ b/views/settings_view.php
@@ -120,4 +120,4 @@ class SettingsView extends View
 <?php
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/views/signin_view.php b/views/signin_view.php
index 55b79e9..7a5db0d 100755
--- a/views/signin_view.php
+++ b/views/signin_view.php
@@ -66,7 +66,14 @@ class SigninView extends View
         <h1 class="logo"><a href="./?<?php e(CSRF_TOKEN."=".$data[CSRF_TOKEN])
                 ?>"><img src="<?php e($logo); ?>" alt="Yioop!"
                 /></a><span> - <?php e(tl('signin_view_signin')); ?></span></h1>
-        <form method="post" action="#">
+        <?php if (isset($_SESSION['salt_value']) && ($_SESSION['COUNT'] == 1))
+        {?>
+           <form action="http://localhost/yioop/?c=admin" method="post"
+                id="form1" onsubmit="generateKeys('form1','password',
+                '<?php echo $_SESSION['salt_value'];  ?>')">
+        <?php } else {?>
+        <form  id="form1" method="post" action="#">
+        <?php } ?>
         <div class="login">
             <table>
             <tr>
@@ -113,7 +120,18 @@ class SigninView extends View
         </div>
         </div>
         <div class='landing-spacer'></div>
+        <div class='landing-spacer'></div>
+        <?php  if ( isset($_SESSION['salt_value']) && ($_SESSION['COUNT'] > 1)) {  ?>
+        <div id="hidden_form_container" style="display:none;"></div>
+        <script type="text/javascript" >
+            document.addEventListener('DOMContentLoaded', function() {
+            var body = tag(body);
+            body.onload = dynamicForm('form1','<?php echo $_SESSION['salt_value'];
+                ?>','<?php echo $_SESSION['USER_NAME']; ?>');
+            }, false);
+        </script>
         <?php
+        }
     }
 }
 ?>
\ No newline at end of file
-- 
1.8.0.msysgit.0

