现在网站一般对账号密码怎样处理后,传往服务器验证是否正确服务器一般又是怎样验证的b?( 二 )


■网友
目前项目中使用的方式是使用spring security附赠的BCrypt做加密和验证。加密:String password = "XXXXX";String encodedPassword = BCrypt.hashpw(BCrypt.gensalt());校验:String userId = "xxxx";String password = "xxxx";User user = userService.findByUserId(userId);if ((null == user) || (!BCrypt.checkpw(password, user.getPassword())){ throw new IllegalStatementException("Username or password is not correct.");} else { // do something}优点:BCrypt相对安全一些,可以自行设置加密程度。缺点:BCrypt的消耗CPU多一点,验证的速度稍慢一点
■网友
反对下匿名用户直接传密码的方式。可以自行百度Kerberos 三头犬协议。。 但凡是把明文密码在网络上丢来丢去的都不是安全的做法,中间很容易被劫持。


推荐阅读