From 3b06ee0d381dc1be5f40ca98ad4278046d869d21 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 17 Nov 2019 20:57:39 +0100 Subject: checked in initial customized verison for Archlinux32 --- addons/copyable_captcha.php | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 addons/copyable_captcha.php (limited to 'addons/copyable_captcha.php') diff --git a/addons/copyable_captcha.php b/addons/copyable_captcha.php new file mode 100644 index 0000000..8f136d9 --- /dev/null +++ b/addons/copyable_captcha.php @@ -0,0 +1,104 @@ +bind('register_after_validation', array($this, 'hook_register_after_validation')); + $manager->bind('register_before_header', array($this, 'hook_register_before_header')); + $manager->bind('register_before_submit', array($this, 'hook_register_before_submit')); + } + + function load_lang() + { + global $pun_user; + + if (isset($this->lang)) return; + + $user_lang = file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/copyable_captcha.php') + ? $pun_user['language'] + : 'English'; + require PUN_ROOT.'lang/'.$user_lang.'/copyable_captcha.php'; + + $this->lang = $lang_copyable_captcha; + } + + function hook_register_after_validation() + { + global $errors, $cookie_name, $cookie_seed; + + if (isset($_POST['req_word']) && isset($_COOKIE[$cookie_name.'_captcha']) && substr_count($_COOKIE[$cookie_name.'_captcha'], '-') === 1) { + list($hash, $time) = explode('-', $_COOKIE[$cookie_name.'_captcha']); + $word = $_POST['req_word']; + if ((int)$time <= time() - 120 || $hash !== sha1(strtolower($word).$cookie_seed.'secret'.$time)) { + $this->load_lang(); + $errors[] = $this->lang['Captcha error']; + } + } else { + $this->load_lang(); + $errors[] = $this->lang['Captcha error']; + } + } + + + function hook_register_before_header() + { + global $required_fields, $errors, $cookie_name, $cookie_seed; + + $this->load_lang(); + $required_fields['req_word'] = $this->lang['Captcha']; + + $time = time(); + $word = random_pass(mt_rand(4, 6)); + $hash = sha1(strtolower($word).$cookie_seed.'secret'.$time); + forum_setcookie($cookie_name.'_captcha', $hash.'-'.$time, $time + 120); + + $array = str_split($word); + $mixin = random_pass(mt_rand(1, 3)); + $i = -1; + $this->styles = ''; + foreach (str_split($mixin) as $ch) { + $i = mt_rand($i+1, count($array)); + array_splice($array, $i, 0, $ch); + $this->styles .= '.masq i:nth-child('.($i + 1).'){display:none;} '; + } + $this->spans = ''.implode('', $array).''; + } + + + function hook_register_before_submit() + { + global $lang_common; + + $this->load_lang(); + +?> +
+
+ lang['Captcha legend'] ?> +
+ +

lang['Captcha info'], $this->spans) ?>

+ +
+
+
+