codeigniter +需要字母和数字的密码 [英] codeigniter + require letters and numbers in password

查看:214
本文介绍了codeigniter +需要字母和数字的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用表单验证来要求具有BOTH字母和数字字符的密码。这里是我到目前为止所做的:

I'd like to use form validation to require a password that has BOTH alpha and numeric characters. Here's what I've come up with so far:

$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]|min_length[8]|alpha_numeric');

问题是alpha_numeric要求密码只包含字母或数字,需要两者。

The issue is that "alpha_numeric" requires that the password only contain letters or numbers, it doesn't require both. Going for the stronger password option here.

推荐答案

您可以设置回呼

public function password_check($str)
{
   if (preg_match('#[0-9]#', $str) && preg_match('#[a-zA-Z]#', $str)) {
     return TRUE;
   }
   return FALSE;
}

然后,更新规则以使用它:

Then, update your rule to use it:

$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]|min_length[8]|alpha_numeric|callback_password_check');

这篇关于codeigniter +需要字母和数字的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆