检查哈希有效性

时间:2015-04-27 13:01:54

标签: php yii hash yii2

我尝试根据存储在数据库中的无效哈希来验证密码。在这种情况下,我的应用程序会因false异常而死亡,而不是Invalid hash(如我所料)。

是否有任何Yii2内置的方法来验证哈希值,然后再将其提供给validatePassword,以便更温和地处理这种情况?

或者我唯一的方法是复制validatePassword使用的代码:

if (!preg_match('/^\$2[axy]\$(\d\d)\$[\.\/0-9A-Za-z]{22}/', $hash, $matches) || $matches[1] < 4 || $matches[1] > 30) {
    throw new InvalidParamException('Hash is invalid.');
}

到我自己的代码,当哈希无效时,根本不调用validatePassword

1 个答案:

答案 0 :(得分:1)

您始终可以在密码验证中使用public static void updateTextTabHost(TabHost tabHost) { TextView textview0 = (TextView)tabHost.getTabWidget() .getChildAt(0).findViewById(android.R.id.title); TextView textview1 = (TextView) tabHost.getTabWidget() .getChildAt(1).findViewById(android.R.id.title); TextView textview2 = (TextView) tabHost.getTabWidget() .getChildAt(2).findViewById(android.R.id.title); textview0.setText("yourTest0"); textview1.setText("yourTest1"); textview2.setText("yourTest2"); } - try阻止:

catch

类似的东西,但为什么你甚至想要尝试验证哈希是否已经格式错误?也许有些罪犯会在那里传递不好的东西,可以通过你的登录等。

相关问题