hibernate md5加密
- 作者: 众泰保安队长
- 来源: 51数据库
- 2021-01-08
是在宿主语言里加密的,如用java开发的可以用java的MD5。C++也有对应的MD5加密类。
跟数据库无关,数据库只是存储加密后的密码,记得把字段长度设为32位(如果没记错的话^_^),MD5加密后的字符串长度.
去网上查:java md5.
public static string md5(string str,int code)
{
if(code==16) //16位md5加密(取32位加密的9~25字符)
{
return system.web.security.formsauthentication.hashpasswordforstoringinconfigfile(str,"md5").tolower().substring(8,16) ;
}
else //32位加密
{
return system.web.security.formsauthentication.hashpasswordforstoringinconfigfile(str,"md5").tolower();
}
}
使用该函数加密,str是原始字符串,函数返回加密后的字符串
在注册的时候,将密码加密存入数据库,用户登录的时候,先将输入的密码进行md5加密,然后和数据库里面的md5值进行判断。
跟数据库无关,数据库只是存储加密后的密码,记得把字段长度设为32位(如果没记错的话^_^),MD5加密后的字符串长度.
去网上查:java md5.
public static string md5(string str,int code)
{
if(code==16) //16位md5加密(取32位加密的9~25字符)
{
return system.web.security.formsauthentication.hashpasswordforstoringinconfigfile(str,"md5").tolower().substring(8,16) ;
}
else //32位加密
{
return system.web.security.formsauthentication.hashpasswordforstoringinconfigfile(str,"md5").tolower();
}
}
使用该函数加密,str是原始字符串,函数返回加密后的字符串
在注册的时候,将密码加密存入数据库,用户登录的时候,先将输入的密码进行md5加密,然后和数据库里面的md5值进行判断。
推荐阅读
