首页 > 解决方案 > 在 Spring 安全性中,matches 函数如何返回 false?

问题描述

我不明白为什么我的 BCryptPasswordEncoder 匹配函数在此处返回 false,从而导致身份验证失败。我正在使用hibernate和Spring5,当我对密码进行编码时,匹配后它返回false。

String randomPassword="admin";

logger.info("Random Password " + randomPassword);

String encodedPassword=bCrypt.encode("randomPassword"); 
logger.info("Encoded Random Password " + encodedPassword);

Boolean b = bCrypt.matches(randomPassword, encodedPassword);

System.out.println("This should be true( " + b + " )");

标签: javaspringspring-mvcspring-security

解决方案


您编码错误的值。

线

String encodedPassword=bCrypt.encode("randomPassword");

应该

String encodedPassword=bCrypt.encode(randomPassword);.


推荐阅读