👋🏼Welcome to my WP-Host blog where I am excited to share my knowledge and expertise on WordPress hosting and website construction tutorials with you. Let’s connect and learn from each other! You can reach me at info@yrshare.com.

(如果你会中文,可以点击微信图标与我联系。)

扫一扫加我

注:因个人英文水平有限,所以暂时只能为懂中文的朋友提供wordpress建站服务

微信:18200592859 或 yrwordpress

Add login and registration verification codes to WordPress websites (increase website installation performance)

Add login and registration verification codes to WordPress websites (increase website installation performance)-WP-Host

Add login and registration verification codes to WordPress websites (increase website installation performance): In theory, as long as there is enough computing power and time, hackers can break through any website and obtain the account password of the website.

So it is very necessary for us to add some security measures to the website. If you are using Site Ground hosting, their Site Ground Security plugin can protect your website very well, you can restrict login, set up 2FA authentication, etc.

If you are using other wordpress hosts, or the website does not have a security plug-in installed, you can add login and registration verification codes to the website through the method I shared today, which can prevent the website from being hacked to a certain extent.

【WP-Host/悦然wordpress建站】

Next, I will share with you two pieces of code, which can add verification codes to the WordPress login page and registration page respectively.

Similarly, you only need to add it to the Functions.php file of the current wordpress website building theme, or you can add it to the Code Snippets plugin.

//Background login math verification code
function rhymo_add_login_fields() {
  //Get two random numbers, range 0~9
  $num1=rand(0,9);
  $num2=rand(0,9);
  //specific content in the final page
      echo "<p><label for='math' class='small'>Verification Code
</label><br /> <input type='text' name='sum' placeholder='$num1 + $num2 = ?' class='input' value='' size='25' tabindex='4'>"
  ."<input type='hidden' name='num1' value='$num1'>"
  ."<input type='hidden' name='num2' value='$num2'></p>";
}
add_action('login_form','rhymo_add_login_fields');
function login_val() {
  $sum=$_POST['sum'];//User Submitted Calculations
  switch($sum){
    //Get the correct calculation result and jump out directly
    case $_POST['num1']+$_POST['num2']:break;
    //Error message when no result is filled
    case null:wp_die('wrong: please enter verification code.');break;
    //Error message when calculation is wrong
    default:wp_die('wrong: Verification code error, please try again.');
  }
}
add_action('login_form_login','login_val');
//Wordpress new user registration random math captcha
function add_security_question_fields() {
//Get two random numbers, range 0~9
   $num1=rand(0,9);
   $num2=rand(0,9);
//specific content in the final page
   echo "<p><label for='math' class='small'>verification code:$num1 + $num2 = ? </label><input type='text' name='sum' class='input' value='' size=
'25'>"    ."<input type='hidden' name='num1' value='$num1'>"
    ."<input type='hidden' name='num2' value='$num2'></p>";}
    add_action('register_form','add_security_question_fields');
    add_action( 'register_post', 'add_security_question_validate', 10, 3 );
    function add_security_question_validate( $sanitized_user_login, $user_email, $errors) {
    $sum=$_POST['sum'];//User Submitted Calculations
    switch($sum){
//Get the correct calculation result and jump out directly
    case $_POST['num1']+$_POST['num2']:break;
//Error message when no result is filled
    case null:wp_die('Error: Please enter the verification code!');break;
//Error message when calculation is wrong
    default:wp_die('Error: Verification code error, please try again!');}}
add_action( 'add_security_question','register_form' );

接下来我将为您分享两个段代码,它们分别可以给wordpress登陆页面和注册页面添加验证码。同样你只需要把它添加到当前wordpress建站主题的Functions.php文件中即可,或者也可以添加到Code Snippets插件中。

//后台登陆数学验证码
function rhymo_add_login_fields() {
  //获取两个随机数, 范围0~9
  $num1=rand(0,9);
  $num2=rand(0,9);
  //最终网页中的具体内容
      echo "<p><label for='math' class='small'>验证码</label><br /> <input type='text' name='sum' placeholder='$num1 + $num2 = ?' class='input' value='' size='25' tabindex='4'>"
  ."<input type='hidden' name='num1' value='$num1'>"
  ."<input type='hidden' name='num2' value='$num2'></p>";
}
add_action('login_form','rhymo_add_login_fields');
function login_val() {
  $sum=$_POST['sum'];//用户提交的计算结果
  switch($sum){
    //得到正确的计算结果则直接跳出
    case $_POST['num1']+$_POST['num2']:break;
    //未填写结果时的错误讯息
    case null:wp_die('错误: 请输入验证码.');break;
    //计算错误时的错误讯息
    default:wp_die('错误: 验证码错误,请重试.');
  }
}
add_action('login_form_login','login_val');
//WordPress新用户注册随机数学验证码
function add_security_question_fields() {
//获取两个随机数, 范围0~9
   $num1=rand(0,9);
   $num2=rand(0,9);
//最终网页中的具体内容
   echo "<p><label for='math' class='small'>验证码:$num1 + $num2 = ? </label><input type='text' name='sum' class='input' value='' size=
'25'>"    ."<input type='hidden' name='num1' value='$num1'>"
    ."<input type='hidden' name='num2' value='$num2'></p>";}
    add_action('register_form','add_security_question_fields');
    add_action( 'register_post', 'add_security_question_validate', 10, 3 );
    function add_security_question_validate( $sanitized_user_login, $user_email, $errors) {
    $sum=$_POST['sum'];//用户提交的计算结果
    switch($sum){
//得到正确的计算结果则直接跳出
    case $_POST['num1']+$_POST['num2']:break;
//未填写结果时的错误讯息
    case null:wp_die('错误:请输入验证码!');break;
//计算错误时的错误讯息
    default:wp_die('错误:验证码错误,请重试!');}}
add_action( 'add_security_question','register_form' );
WordPress Hosting / 悦然wordpress建站

WordPress Hosting / 悦然wordpress建站

【WordPress Hosting / 悦然wordpress建站】I am a WordPress hobby from China, and I like to communicate with friends from all over the world to learn WordPress website building and maintenance related knowledge.