_binary From 2f1b757dcd5276710304a1b264ba69b2bcea70c6 Mon Sep 17 00:00:00 2001
From: Akash Patel <akash3664@yahoo.com>
Date: Tue, 13 May 2014 14:49:57 -0700
Subject: [PATCH] ZKP feature

---
 configs/config.php                                 |   7 +
 configs/createdb.php                               |   8 +-
 controllers/admin_controller.php                   |  93 ++-
 controllers/components/accountaccess_component.php |  53 +-
 controllers/components/system_component.php        |   6 +
 controllers/register_controller.php                | 127 ++--
 locale/en-US/configure.ini                         |   9 +
 models/profile_model.php                           |  24 +-
 models/signin_model.php                            |  61 +-
 models/user_model.php                              |  20 +-
 scripts/basic.js                                   |  12 +-
 scripts/bigInt.js                                  | 679 +++++++++++++++++++++
 scripts/classifiers.js                             |   2 +-
 scripts/hashcaptcha.js                             | 201 ------
 scripts/mix.js                                     |   2 +-
 scripts/sha1.js                                    | 231 +++++++
 scripts/zkp.js                                     | 208 +++++++
 tests/sha1_test.php                                |   1 +
 views/elements/manageusers_element.php             |   8 +-
 views/elements/serversettings_element.php          |  18 +-
 views/recover_view.php                             |  76 ++-
 views/register_view.php                            |  10 +
 views/signin_view.php                              |  20 +-
 24 files changed, 1549 insertions(+), 327 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 486daba..1ce2302 100755
--- a/configs/config.php
+++ b/configs/config.php
@@ -128,6 +128,12 @@ define('TEXT_CAPTCHA', 1);
 /** Captcha Mode Possibility*/
 define('HASH_CAPTCHA', 2);
 
+/** Authentication Mode Possibility*/
+define('NORMAL_AUTHENTICATION', 1);
+
+/** Authentication Mode Possibility*/
+define('ZKP_AUTHENTICATION', 2);
+
 if(file_exists(WORK_DIRECTORY.PROFILE_FILE_NAME)) {
     require_once(WORK_DIRECTORY.PROFILE_FILE_NAME);
     define('PROFILE', true);
@@ -158,6 +164,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);
diff --git a/configs/createdb.php b/configs/createdb.php
index d0ba0ab..8f66048 100755
--- a/configs/createdb.php
+++ b/configs/createdb.php
@@ -94,11 +94,13 @@ if(!$profile_model->createDatabaseTables($db, $dbinfo)) {
 $db->execute("INSERT INTO VERSION VALUES (19)");
 
 $creation_time = microTimestamp();
-
+//numerical value of the blank password
+$password_ZKP = '155213078793840034857994277066753650314928358318183864917136'.
+                '6591924563160025427690176245139603025';
 //default account is root without a password
 $sql ="INSERT INTO USERS VALUES (".ROOT_ID.", 'admin', 'admin','root',
         'root@dev.null', '".crawlCrypt('')."', '".ACTIVE_STATUS.
-        "', '".crawlCrypt('root'.AUTH_KEY.$creation_time)."','$creation_time')";
+        "', '".crawlCrypt('root'.AUTH_KEY.$creation_time)."', '$creation_time', '$password_ZKP')";
 
 $db->execute($sql);
 // public account is an inactive account for used for public permissions
@@ -106,7 +108,7 @@ $db->execute($sql);
 $sql ="INSERT INTO USERS VALUES (".PUBLIC_USER_ID.", 'all', 'all','public',
         'public@dev.null', '".crawlCrypt('')."', '".INACTIVE_STATUS.
         "', '".crawlCrypt('public'.AUTH_KEY.$creation_time)."',
-        '$creation_time')";
+        '$creation_time','$password_ZKP')";
 $db->execute($sql);
 
 //default public group with group id 1
diff --git a/controllers/admin_controller.php b/controllers/admin_controller.php
index 610fc24..01e507a 100755
--- a/controllers/admin_controller.php
+++ b/controllers/admin_controller.php
@@ -62,6 +62,12 @@ foreach(glob(BASE_DIR."/lib/processors/*_processor.php") as $filename) {
 class AdminController extends Controller implements CrawlConstants
 {
     /**
+     * Number of Fiat-shamir iterations in case of ZKP authentication
+     * @var int
+     */
+    const FIAT_SHAMIR_ITERATIONS = 10;
+    
+    /**
      * Says which activities (roughly methods invoke from the web) this
      * controller will respond to (note: more activities will be loaded from
      * components)
@@ -87,8 +93,15 @@ class AdminController extends Controller implements CrawlConstants
      */
     function processRequest()
     {
+        $profile_model = $this->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
+        if (!isset($_SESSION['AUTH_COUNT'])) {
+                $_SESSION['AUTH_COUNT'] = 1;
+        }
+        if($profile['AUTHENTICATION_MODE'] == NORMAL_AUTHENTICATION) {
+                $_SESSION['AUTH_COUNT'] = self::FIAT_SHAMIR_ITERATIONS;
+        }
         $data = array();
-
         if(!PROFILE) {
             return $this->configureRequest();
         }
@@ -116,32 +129,39 @@ 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;
+                if($profile['AUTHENTICATION_MODE'] == ZKP_AUTHENTICATION) {
+                    $_SESSION['AUTH_COUNT'] = $_SESSION['AUTH_COUNT'] + 1;
                 }
-
-                $_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['AUTH_COUNT'] == self::FIAT_SHAMIR_ITERATIONS) {
+                    $_SESSION['AUTH_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['AUTH_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,12 @@ class AdminController extends Controller implements CrawlConstants
             $data["ADMIN"] = false;
         }
         if($view == 'signin') {
+            if($profile['AUTHENTICATION_MODE'] == ZKP_AUTHENTICATION) {
+                $_SESSION['SALT_VALUE'] = rand(0, 1);
+                $data['INCLUDE_SCRIPTS'] = array("zkp", "bigInt", "sha1");
+            } else {
+                 unset($_SESSION['SALT_VALUE']);
+            }
             unset($_SESSION['USER_ID']);
             $data[CSRF_TOKEN] = $this->generateCSRFToken(
                 $_SERVER['REMOTE_ADDR']);
@@ -188,9 +214,22 @@ class AdminController extends Controller implements CrawlConstants
      */
     function checkSignin()
     {
-        $result = $this->model("signin")->checkValidSignin(
-        $this->clean($_REQUEST['u'], "string"),
-        $this->clean($_REQUEST['p'], "string") );
+        $profile_model = $this->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
+        if($profile['AUTHENTICATION_MODE'] == NORMAL_AUTHENTICATION) {
+            $result = $this->model("signin")->checkValidSignin(
+            $this->clean($_REQUEST['u'], "string"),
+            $this->clean($_REQUEST['p'], "string") );
+        } else {
+            $result = $this->model("signin")->checkValidSigninForZKP(
+            $this->clean($_REQUEST['u'], "string"),
+            $this->clean($_REQUEST['x1'], "string"),
+            $this->clean($_REQUEST['y1'], "string"),
+            $_SESSION['SALT_VALUE']);
+            if(!$result){
+             $_SESSION['AUTH_COUNT'] = 1;
+            }
+        }
         return $result;
     }
 
diff --git a/controllers/components/accountaccess_component.php b/controllers/components/accountaccess_component.php
index cd78d98..8cac745 100644
--- a/controllers/components/accountaccess_component.php
+++ b/controllers/components/accountaccess_component.php
@@ -70,6 +70,8 @@ class AccountaccessComponent extends Component
     function manageAccount()
     {
         $parent = $this->parent;
+        $profile_model = $parent->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
         $signin_model = $parent->model("signin");
         $group_model = $parent->model("group");
         $user_model = $parent->model("user");
@@ -146,9 +148,16 @@ class AccountaccessComponent extends Component
                         return $data;
                     }
                     if(isset($data['EDIT_PASSWORD'])) {
-                        $signin_model->changePassword($username,
-                            $parent->clean($_REQUEST['new_password'],
-                            "string"));
+                        if($profile['AUTHENTICATION_MODE']
+                             == ZKP_AUTHENTICATION) {
+                            $signin_model->changePasswordZKP($username,
+                                $parent->clean($_REQUEST['new_password'],
+                                "string"));
+                        } else {
+                                $signin_model->changePassword($username,
+                                $parent->clean($_REQUEST['new_password'],
+                                "string"));
+                        }
                     }
                     $user = array();
                     $user['USER_ID'] = $user_id;
@@ -183,6 +192,17 @@ class AccountaccessComponent extends Component
     function manageUsers()
     {
         $parent = $this->parent;
+        $profile_model = $parent->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
+        if($profile['AUTHENTICATION_MODE'] == ZKP_AUTHENTICATION) {
+            $_SESSION['SALT_VALUE'] = rand(0, 1);
+            $_SESSION['AUTH_COUNT'] = 1;
+            $data['INCLUDE_SCRIPTS'] = array("sha1","zkp","bigInt");
+            $data['AUTHENTICATION_MODE'] = ZKP_AUTHENTICATION;
+        } else {
+            $data['AUTHENTICATION_MODE'] = NORMAL_AUTHENTICATION;
+            unset($_SESSION['SALT_VALUE']);
+        }
         $signin_model = $parent->model("signin");
         $user_model = $parent->model("user");
         $group_model = $parent->model("group");
@@ -256,13 +276,23 @@ class AccountaccessComponent extends Component
                         $_REQUEST['status']])) {
                         $_REQUEST['status'] = INACTIVE_STATUS;
                     } else {
-                        $user_model->addUser($username,
-                            $parent->clean($_REQUEST['password'], "string"),
-                            $parent->clean($_REQUEST['first_name'], "string"),
-                            $parent->clean($_REQUEST['last_name'], "string"),
-                            $parent->clean($_REQUEST['email'], "string"),
-                            $_REQUEST['status']
+                        if($profile['AUTHENTICATION_MODE'] == ZKP_AUTHENTICATION) {
+                            $user_model->addUser($username, '',
+                                $parent->clean($_REQUEST['first_name'], "string"),
+                                $parent->clean($_REQUEST['last_name'], "string"),
+                                $parent->clean($_REQUEST['email'], "string"),
+                                $_REQUEST['status'],
+                                $parent->clean($_REQUEST['password'], "string")
                             );
+                        } else {
+                            $user_model->addUser($username,
+                                $parent->clean($_REQUEST['password'], "string"),
+                                $parent->clean($_REQUEST['first_name'], "string"),
+                                $parent->clean($_REQUEST['last_name'], "string"),
+                                $parent->clean($_REQUEST['email'], "string"),
+                                $_REQUEST['status']
+                            );
+                        }
                         $data['USER_NAMES'][$username] = $username;
                         $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                             tl('accountaccess_component_user_added').
@@ -291,6 +321,11 @@ class AccountaccessComponent extends Component
                                     $_REQUEST[$field], "string");
                                 if($tmp != $user[$upper_field]) {
                                     $user[$upper_field] = $tmp;
+                                     if($profile['AUTHENTICATION_MODE'] == 
+                                        ZKP_AUTHENTICATION && $upper_field == "PASSWORD") {
+                                        $user["ZKP_PASSWORD"] = $tmp;
+                                        $user[$upper_field] ='';
+                                    }
                                     if(!isset($_REQUEST['change_filter'])) {
                                         $update = true;
                                     }
diff --git a/controllers/components/system_component.php b/controllers/components/system_component.php
index ce1e774..29e3ee8 100644
--- a/controllers/components/system_component.php
+++ b/controllers/components/system_component.php
@@ -611,6 +611,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(
diff --git a/controllers/register_controller.php b/controllers/register_controller.php
index ede9a69..2e4fd63 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,20 @@ class RegisterController extends Controller implements CrawlConstants
             $visitor_model->updateVisitor(
                 $_SERVER['REMOTE_ADDR'], "captcha_time_out");
         }
+        if($profile['AUTHENTICATION_MODE'] == ZKP_AUTHENTICATION) {
+            $_SESSION['SALT_VALUE'] = rand(0, 1);
+            $_SESSION['AUTH_COUNT'] = 1;
+            $data['INCLUDE_SCRIPTS'] = array("sha1", "zkp", "bigInt");
+        } else {
+            unset($_SESSION['SALT_VALUE']);
+        }
+        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);
@@ -281,7 +299,8 @@ class RegisterController extends Controller implements CrawlConstants
      *      or not
      */
     function processAccountData()
-    {
+    {   $profile_model = $this->model("profile");
+        $profile = $profile_model->getProfile(WORK_DIRECTORY);
         $data = array();
         $this->getCleanFields($data);
         $data['SCRIPT'] = "";
@@ -290,16 +309,28 @@ class RegisterController extends Controller implements CrawlConstants
         {
             case 'no_activation':
                 $data['REFRESH'] = "signin";
-                $user_model->addUser($data['USER'], $data['PASSWORD'],
-                    $data['FIRST'], $data['LAST'], $data['EMAIL']);
+                if($profile['AUTHENTICATION_MODE'] == NORMAL_AUTHENTICATION) {
+                    $user_model->addUser($data['USER'], $data['PASSWORD'],
+                        $data['FIRST'], $data['LAST'], $data['EMAIL']);
+                } else {
+                    $user_model->addUser($data['USER'], '',
+                        $data['FIRST'], $data['LAST'], $data['EMAIL'],
+                        ACTIVE_STATUS, $data['PASSWORD']);
+                }
                 $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                     tl('register_controller_account_created')."</h1>')";
             break;
             case 'email_registration':
                 $data['REFRESH'] = "signin";
-                $user_model->addUser($data['USER'], $data['PASSWORD'],
-                    $data['FIRST'], $data['LAST'], $data['EMAIL'],
-                    INACTIVE_STATUS);
+                if($profile['AUTHENTICATION_MODE'] == NORMAL_AUTHENTICATION) {
+                    $user_model->addUser($data['USER'], $data['PASSWORD'],
+                        $data['FIRST'], $data['LAST'], $data['EMAIL'],
+                        INACTIVE_STATUS);
+                } else {
+                    $user_model->addUser($data['USER'], '',
+                        $data['FIRST'], $data['LAST'], $data['EMAIL'],
+                        INACTIVE_STATUS, $data['PASSWORD']);
+                }
                 $user = $user_model->getUser($data['USER']);
                 $server = new MailServer(MAIL_SENDER, MAIL_SERVER,
                     MAIL_SERVERPORT, MAIL_USERNAME, MAIL_PASSWORD,
@@ -328,9 +359,15 @@ class RegisterController extends Controller implements CrawlConstants
             break;
             case 'admin_activation':
                 $data['REFRESH'] = "signin";
-                $user_model->addUser($data['USER'], $data['PASSWORD'],
-                    $data['FIRST'], $data['LAST'], $data['EMAIL'],
-                    INACTIVE_STATUS);
+                if($profile['AUTHENTICATION_MODE'] == NORMAL_AUTHENTICATION) {
+                    $user_model->addUser($data['USER'], $data['PASSWORD'],
+                        $data['FIRST'], $data['LAST'], $data['EMAIL'],
+                        INACTIVE_STATUS);
+                } else {
+                    $user_model->addUser($data['USER'], '',
+                        $data['FIRST'], $data['LAST'], $data['EMAIL'],
+                        INACTIVE_STATUS, $data['PASSWORD']);
+                }
                 $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                     tl('register_controller_account_request_made')."</h1>');";
                 $server = new MailServer(MAIL_SENDER, MAIL_SERVER,
@@ -439,6 +476,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 +492,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 +649,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("sha1", "hashcaptcha");
         }
         if($profile['CAPTCHA_MODE'] == TEXT_CAPTCHA) {
             $num_captchas = self::NUM_CAPTCHA_QUESTIONS;
@@ -769,8 +810,18 @@ 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;
@@ -1050,25 +1101,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/locale/en-US/configure.ini b/locale/en-US/configure.ini
index 4d977db..35338de 100755
--- a/locale/en-US/configure.ini
+++ b/locale/en-US/configure.ini
@@ -951,6 +951,12 @@ serversettings_element_text_captcha = "Text Captcha"
 ; system_component.php line: 611
 serversettings_element_hash_captcha = "Hash Captcha"
 ;
+; system_component.php line: 615
+serversettings_element_normal_authentication = "Normal Authentication"
+;
+; system_component.php line: 617
+serversettings_element_zkp_authentication = "ZKP Authentication"
+;
 ; system_component.php line: 715
 system_component_configure_use_absolute_path = "Must use an Absolute path for Work Directory"
 ;
@@ -2837,6 +2843,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/profile_model.php b/models/profile_model.php
index 2ce8b4b..4f4b3b7 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}
@@ -361,7 +361,7 @@ EOT;
                 FIRST_NAME VARCHAR(16), LAST_NAME VARCHAR(16),
                 USER_NAME VARCHAR(16) UNIQUE, EMAIL VARCHAR(60),
                 PASSWORD CHAR(60), STATUS INTEGER, HASH CHAR(60),
-                CREATION_TIME VARCHAR(20))",
+                CREATION_TIME VARCHAR(20), ZKP_PASSWORD CHAR(200))",
             "CREATE INDEX USRS_USER_NAME_INDEX ON USERS(USER_NAME)",
             "CREATE TABLE USER_GROUP (USER_ID INTEGER , GROUP_ID INTEGER,
                    STATUS INTEGER, JOIN_DATE NUMERIC(11),
diff --git a/models/signin_model.php b/models/signin_model.php
index bd50044..df71b5c 100755
--- a/models/signin_model.php
+++ b/models/signin_model.php
@@ -60,7 +60,25 @@ class SigninModel extends Model
     function checkValidSignin($username, $password)
     {
         $db = $this->db;
-        $sql = "SELECT USER_NAME, PASSWORD FROM USERS ".
+        $result = $this->getUserDetails($username);
+        if(!$result) {
+            return false;
+        }
+        $row = $db->fetchArray($result);
+        return ($username == $row['USER_NAME'] &&
+            crawlCrypt($password, $row['PASSWORD']) == $row['PASSWORD']) ;
+    }
+    
+    /**
+     * Get user details from database
+     *
+     * @param string $username username
+     * @return array $result array of user data
+     */
+    function getUserDetails($username)
+    {
+        $db = $this->db;
+        $sql = "SELECT USER_NAME, PASSWORD,ZKP_PASSWORD FROM USERS ".
             "WHERE USER_NAME = ? " . $db->limitOffset(1);
         $i = 0;
         do {
@@ -70,13 +88,33 @@ class SigninModel extends Model
             $result = $db->execute($sql, array($username));
             $i++;
         } while(!$result && $i < 2);
+        return $result;
+    }
+    
+    /**
+     * To verify  username and password in case of ZKP authentication.
+     *
+     * @param string $username username
+     * @param string $database_username  username stored in database
+     * @param string $database_password  password stored in database
+     * @return bool  where the password is that of the given user
+     */
+    function checkValidSigninForZKP($username,$x,$y,$e)
+    {
+        $db = $this->db;
+        $result = $this->getUserDetails($username);
         if(!$result) {
             return false;
         }
         $row = $db->fetchArray($result);
-
-        return ($username == $row['USER_NAME'] &&
-            crawlCrypt($password, $row['PASSWORD']) == $row['PASSWORD']) ;
+        $n = "4911896143611633780682402453849989800775189204252065".
+             "7264082207290936669351692953333549721159585615965418".
+             "82926741138174142872698595829944178957090296779606642".
+             "580976458630868510407440881709556568052691";
+        $v = $row['ZKP_PASSWORD'];
+        $rp = bcmul($x, bcmod(bcpow($v, $e), $n));
+        $lp = bcmul($y, $y);
+        return ($username == $row['USER_NAME'] && bccomp($rp, $lp) == 0);
     }
 
     /**
@@ -167,6 +205,21 @@ class SigninModel extends Model
         return $result != false;
     }
 
+    /**
+     *  Changes the password of a given user in case of ZKP authentication
+     *
+     *  @param string $username username of user to change password of
+     *  @param string $password new password for user
+     *  @return bool update successful or not.
+     */
+    function changePasswordZKP($username, $password)
+    {
+        $sql = "UPDATE USERS SET ZKP_PASSWORD=? WHERE USER_NAME = ? ";
+        $result = $this->db->execute($sql,
+            array($password, $username) );
+        return $result != false;
+    }
+
 }
 
 ?>
\ No newline at end of file
diff --git a/models/user_model.php b/models/user_model.php
index bfbf246..4869313 100755
--- a/models/user_model.php
+++ b/models/user_model.php
@@ -291,6 +291,18 @@ class UserModel extends Model
         $db->execute($sql, array($status, $user_id));
     }
 
+    function addUserToUsersTable($username, $password, $firstname='', $lastname='',
+        $email='', $status = ACTIVE_STATUS, $zkp_password='')
+    {
+        $db = $this->db;
+        $sql = "INSERT INTO USERS(FIRST_NAME, LAST_NAME,
+            USER_NAME, EMAIL, PASSWORD, STATUS, HASH, CREATION_TIME,ZKP_PASSWORD) VALUES (
+            ?, ?, ?, ?, ?, ?, ?, ?,?)";
+        $result = $db->execute($sql, array($firstname, $lastname,
+            $username, $email, crawlCrypt($password), $status,
+            crawlCrypt($username.AUTH_KEY.$creation_time), $creation_time,$zkp_password));
+    }
+
     /**
      * Add a user with a given username and password to the list of users
      * that can login to the admin panel
@@ -303,16 +315,16 @@ class UserModel extends Model
      * @return mixed false if operation not successful, user_id otherwise
      */
     function addUser($username, $password, $firstname='', $lastname='',
-        $email='', $status = ACTIVE_STATUS)
+        $email='', $status = ACTIVE_STATUS, $zkp_password='')
     {
         $creation_time = microTimestamp();
         $db = $this->db;
         $sql = "INSERT INTO USERS(FIRST_NAME, LAST_NAME,
-            USER_NAME, EMAIL, PASSWORD, STATUS, HASH, CREATION_TIME) VALUES (
-            ?, ?, ?, ?, ?, ?, ?, ?)";
+            USER_NAME, EMAIL, PASSWORD, STATUS, HASH, CREATION_TIME,ZKP_PASSWORD) VALUES (
+            ?, ?, ?, ?, ?, ?, ?, ?,?)";
         $result = $db->execute($sql, array($firstname, $lastname,
             $username, $email, crawlCrypt($password), $status,
-            crawlCrypt($username.AUTH_KEY.$creation_time), $creation_time));
+            crawlCrypt($username.AUTH_KEY.$creation_time), $creation_time, $zkp_password));
         if(!$user_id = $this->getUserId($username)) {
             return false;
         }
diff --git a/scripts/basic.js b/scripts/basic.js
index 80e840a..616e4e9 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 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..86c71b3
--- /dev/null
+++ b/scripts/bigInt.js
@@ -0,0 +1,679 @@
+/**
+ *  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 input number
+ *  @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 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
+ *
+ *  @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) {
+      b =- (c >> bits_per_element);
+      c += b * radix;
+    }
+    x[i] = c & mask;
+    c = (c >> bits_per_element) - b;
+    if (!c) {
+    return;
+    }
+  }
+}
+
+/*
+ *  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;
+  var 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) {
+      d -= 26;
+    }
+    if (d >= base || d < 0) {
+      break;
+    }
+    multInt(x, base);
+    addBigIntToInt(x, d);
+  }
+  for (k = x.length; k > 0 && !x[k-1]; k --);
+  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 multiply bigInt with Int.
+ *
+ *  @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);
+}
+
+/*
+ *  To perform linear combination
+ *  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);
+  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;
+      } 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 shift operation on y and add it to the x
+ *
+ *  @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;
+  }
+}
+
+/*
+ *  It right shifts the x by given number of bits and check
+ *  whether it is greater than 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 left shift the y by given number of bits and performs
+ *  subtraction operation. 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/classifiers.js b/scripts/classifiers.js
index f4a1071..5ea9177 100644
--- a/scripts/classifiers.js
+++ b/scripts/classifiers.js
@@ -836,4 +836,4 @@ var Classifier = (function() {
     }
 
     return self;
-})();
+})();
\ 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 e236e35..246424e 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..7b36971
--- /dev/null
+++ b/scripts/zkp.js
@@ -0,0 +1,208 @@
+/**
+ *  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 user_name and passsword in the cookies. This cookie is used in the
+ *  ZKP authentication
+ *
+ *  @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 passsword from the cookies. This cookie is used in the
+ *  ZKP authentication
+ *
+ *  @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 = 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 = elt(form1);
+    var password = elt(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);
+    var newInput1 = ce('input');
+    newInput1.type = 'hidden';
+    newInput1.name = 'x1';
+    newInput1.value = bigInt2str(x,10);
+    var newInput2 = ce('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 = elt(password);
+    var repassword1 = elt(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..98afbb4 100644
--- a/tests/sha1_test.php
+++ b/tests/sha1_test.php
@@ -66,6 +66,7 @@ class Sha1Test extends JavaScriptTest
         <div id="sha1Test">
         </div>
         <head>
+        <script type="text/javascript" src="../scripts/sha1.js" ></script>
         <script type="text/javascript" src="../scripts/hashcaptcha.js" ></script>
         <script type="text/javascript">
         var input_array = <?php echo $js_array; ?>;
diff --git a/views/elements/manageusers_element.php b/views/elements/manageusers_element.php
index fcc8efa..386e487 100644
--- a/views/elements/manageusers_element.php
+++ b/views/elements/manageusers_element.php
@@ -193,7 +193,13 @@ class ManageusersElement extends Element
             e("<h2>".tl('manageusers_element_add_user'). "</h2>");
         }
         ?>
-        <form id="user-form" method="post" action='#' autocomplete="off">
+       <?php if($data['AUTHENTICATION_MODE'] == ZKP_AUTHENTICATION) { ?>
+                <form action="" method="post"
+                    onsubmit="registration('pass-word','retype-password')">
+                <input type="hidden" name="numericPassword" id="numericPassword"/>
+       <?php } else { ?>
+               <form id="user-form" method="post" action='#' autocomplete="off">
+       <?php }?>
         <input type="hidden" name="c" value="admin" />
         <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
             e($data[CSRF_TOKEN]); ?>" />
diff --git a/views/elements/serversettings_element.php b/views/elements/serversettings_element.php
index 2d4bb08..334fa7c 100644
--- a/views/elements/serversettings_element.php
+++ b/views/elements/serversettings_element.php
@@ -246,8 +246,22 @@ class ServersettingsElement extends Element
                 </label></legend>
                     <?php $this->view->helper("options")->render(
                         "captcha-setting", "CAPTCHA_MODE",
-                       $data['CAPTCHA_MODES'],
-                     $data['CAPTCHA_MODE']);
+                         $data['CAPTCHA_MODES'],
+                         $data['CAPTCHA_MODE']);
+                ?>
+            </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>
diff --git a/views/recover_view.php b/views/recover_view.php
index 57fe7e6..7af9f7f 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..c49d7c8 100755
--- a/views/register_view.php
+++ b/views/register_view.php
@@ -73,6 +73,14 @@ 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" />
@@ -233,6 +241,7 @@ class RegisterView 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);
@@ -242,5 +251,6 @@ class RegisterView extends View
         </script>
     <?php
         }
+      }
     }
     ?>
diff --git a/views/signin_view.php b/views/signin_view.php
index 55b79e9..e854f79 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['AUTH_COUNT'] == 1)) { ?>
+                <form action="./?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>
+        <?php  if ( isset($_SESSION['SALT_VALUE'])
+                && ($_SESSION['AUTH_COUNT'] > 1)) {  ?>
+        <div id="hidden_form_container"></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

