Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to do MD5 encryption in JSP for password login and registration?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question How to do MD5 encryption in JSP for password login and registration?

    Guys, how to do MD5 encryption in JSP for password login and registration?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: How to do MD5 encryption in JSP for password login and registration?

    What have you tried? Where are you stuck?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: How to do MD5 encryption in JSP for password login and registration?

    <%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.security.MessageDigest"%>
    <html>
    <body>
    This jsp code shows an example of a functioning md5 hash.<br>
    The plaintext password is 'password' and is hard coded.<br>
    The MD5 hash version of 'password' is '5f4dcc3b5aa765d61d8327deb882cf99'<br>
    and is calculated each time the page is loaded.<br><br>
    <%
     
    // Set password string, and print it out
    String passwd = "password";
    out.println("Password is: " + passwd + ".<br>");
     
    // Create a new instance of MessageDigest, using MD5. SHA and other
    // digest algorithms are also available.
    MessageDigest alg = MessageDigest.getInstance("MD5");
     
    // Reset the digest, in case it's been used already during this section of code
    // This probably isn't needed for pages of 210 simplicity
    alg.reset(); 
     
    // Calculate the md5 hash for the password. md5 operates on bytes, so give
    // MessageDigest the byte verison of the string
    alg.update(passwd.getBytes());
     
    // Create a byte array from the string digest
    byte[] digest = alg.digest();
     
    // Convert the hash from whatever format it's in, to hex format
    // which is the normal way to display and report md5 sums
    // This is done byte by byte, and put into a StringBuffer
    StringBuffer hashedpasswd = new StringBuffer();
    String hx;
    for (int i=0;i<digest.length;i++){
    	hx =  Integer.toHexString(0xFF & digest[i]);
    	//0x03 is equal to 0x3, but we need 0x03 for our md5sum
    	if(hx.length() == 1){hx = "0" + hx;}
    	hashedpasswd.append(hx);
    }
     
    // Print out the string hex version of the md5 hash
    out.println("MD5 version is: " + hashedpasswd.toString() + "<br>");
    %>
    </body>
    </html>

    i find this code, then i use this for my encryption with little modified, and in this tutorial said, this code is too old, and have some security issue, is there something wrong with this code? because i try it and it work well

    i want to ask how about decrypt it?
    i need to decrypt the password while my user forget the password, and i use it to send it for them

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: How to do MD5 encryption in JSP for password login and registration?

    Why do you want to send their password back to them? Doesn't that defeat the point?

    If they forget their password, just reset it to some generated random password and send them that. Then they can change it to whatever they want.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. The Following User Says Thank You to KevinWorkman For This Useful Post:

    sadaharu (June 21st, 2012)

  6. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: How to do MD5 encryption in JSP for password login and registration?

    Quote Originally Posted by KevinWorkman View Post
    Why do you want to send their password back to them? Doesn't that defeat the point?

    If they forget their password, just reset it to some generated random password and send them that. Then they can change it to whatever they want.
    ooh yea! goodm nice advice man! i will start a new topic, since this topic is about MD5 encryption

Similar Threads

  1. [SOLVED] Need help with IDEA Encryption
    By finalforce in forum Algorithms & Recursion
    Replies: 1
    Last Post: June 4th, 2012, 04:41 AM
  2. Hello.. need help in encryption process
    By apisz8701 in forum Member Introductions
    Replies: 0
    Last Post: February 13th, 2011, 05:03 AM
  3. Java Encryption
    By xxcorrosionxx in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 9th, 2011, 04:12 AM
  4. Java password encryption
    By jmorr212 in forum JDBC & Databases
    Replies: 2
    Last Post: January 29th, 2011, 02:33 AM
  5. How to write registration module
    By speedzojie in forum Java Theory & Questions
    Replies: 3
    Last Post: May 10th, 2010, 04:03 AM