👋🏼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

为WordPress网站添加登录和注册验证码(增加网站安装性能)

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

为WordPress网站添加登录和注册验证码(增加网站安装性能):理论上,只要有足够的计算能力和时间,黑客都可以攻破任何网站,获取该网站的账号密码。

所以我们在网站上增加一些安全措施是非常有必要的。如果您正在使用 Site Ground hosting,他们的SiteGround Security插件可以很好的保护你的网站,你可以限制登录,设置2FA认证等。

如果你使用的是其他wordpress主机,或者网站没有安装安全插件,可以通过我今天分享的方法给网站添加登录和注册验证码,这可以在一定程度上防止网站被攻破。

【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建站】我是来自中国的wordpress爱好,喜欢与世界各地的朋友一起交流学习wordpress建站和维护相关知识。