mysql select 转换_在mysql的select查询中将varbinary值转换成字符串?

根据这个

answer

,我应该保存我的

bcrypt哈希密码,

passHash

作为一个

BINARY

BINARY(60)

(我选择

二进制(60)

)当它存储在mysql表中时(我将它存储在一个名为

帕沙什

)

现在,当我选择并检索它时

帕沙什

从我的表到Java的列值,现在是

byte[]

数据类型。

然后我怎么把它转换回它的

窗体以便我可以使用

validateLogin()

方法如下:

//Validate username and password login

public boolean validateLogin(String username, String userpass)

{

boolean status = false;

PreparedStatement pst = null;

ResultSet rs = null;

User user = new User(); //This is my Java bean class

try(Connection connect= DBConnection.getConnection())

{

//Here, passHash is stored as VARBINARY(60)

pst = connect.prepareStatement("SELECT * FROM user WHERE username=? and passHash=?;");

pst.setString(1, username);

pst.setString(2, userpass);

//Here's where I'm having difficulty because `passHash` column in my user table is VARBINARY(60) while `userpass` is a String

rs = pst.executeQuery();

status = rs.next();

}

catch (SQLException e)

{

e.printStackTrace();

}

return status; //status will return `true` if `username` and `userpass` matches what's in the columns

}

参数

username

userpass

用于获取用户在我的

Login.jsp

形式:

String username = request.getParameter("username");

String userpass = request.getParameter("userpass");

编辑

:我的Bcrypt代码如下:

//returns a hashed String value

public static String bCrypt (String passPlain) {

return BCrypt.hashpw(passPlain, BCrypt.gensalt(10));

}

//Returns a true if plain password is a match with hashed password

public static Boolean isMatch(String passPlain, String passHash){

return (BCrypt.checkpw(passPlain, passHash));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值