Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MD5 Encrypt in java

  • 26-02-2009 10:52pm
    #1
    Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭


    Hi
    How would I go about MD5 encrypting a string in java?
    I have a password which is encrypted in MD5 in a database so Id like to match the password entered in by the user with the MD5 encrypted password in the database and if they match then the user is logged in.

    So for the check in my java code for the query I tried
    Select * from users where user_name="+username+" and password="+MD5Crypt(password)

    That doesn't work because it's wrong.
    Java surely has some built in function to md5 encrypt a string hasn't it?
    Can you help?
    thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 222 ✭✭mecco


    if you look at the class in this link: http://www.anyexample.com/programming/java/java_simple_class_to_compute_md5_hash.xml, you should be able to see how to use the MD5 capabilities built into Java. I havent tested the class, but it appears to compute the hash for you and convert the byte array (provided by the default Java class) into a string. It gives an example how to call the code too.

    Again I havent tested it so your mileage may vary :)


  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    Thanks that works grand.


  • Registered Users, Registered Users 2 Posts: 555 ✭✭✭baztard


    I'd be careful there, MD5 is a message digest / hash generally used to check if a file has changed or been tampered with in transit. I'm no expert but I dont think it should be used for encrypting passwords.


  • Closed Accounts Posts: 8,015 ✭✭✭CreepingDeath


    baztard wrote: »
    I'd be careful there, MD5 is a message digest / hash generally used to check if a file has changed or been tampered with in transit. I'm no expert but I dont think it should be used for encrypting passwords.

    One way hashing of passwords is more secure than encrypting.
    Encryption is a two way process, hashing / message digesting is a one way process. There's no way of working out the arbitrary length string from a fixed length digest without brute force.

    There's a clear difference between encryption and message digesting.


Advertisement