質問

How to convert String from input text to md5? I have no clue.

This is part of my .jsp

<tr>
<td><spring:message code="password" text="default text" /></td>
<td>:</td>
<td><input type="password" name="password" required></td>

and this is my controller

@RequestMapping(value="/admin/addUser.html", method=RequestMethod.POST)
public ModelAndView createUserAdmin(@ModelAttribute UserAdmin useradmin, ModelMap model)throws Exception
{
    userService.save(useradmin);
    model.addAttribute("successAdd", "true");
    return listUserAdmin(model);
}

Thanks for any help :)

役に立ちましたか?

解決

Use this method pass string as parameter it will return MD5 as return string. Store that string in database.

public static String getMD5(String data) throws NoSuchAlgorithmException
    { 
MessageDigest messageDigest=MessageDigest.getInstance("MD5");

        messageDigest.update(data.getBytes());
        byte[] digest=messageDigest.digest();
        StringBuffer sb = new StringBuffer();
        for (byte b : digest) {
            sb.append(Integer.toHexString((int) (b & 0xff)));
        }
        return sb.toString();
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top