Commit 3e23f483 authored by Rikysamuel's avatar Rikysamuel
Browse files

add md5 function, fix loginpanel

parent 9a837e3a
......@@ -29,14 +29,13 @@ dist.jar=${dist.dir}/GrandQuest.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.json-simple-1.1.1.jar-1=D:\\AFIK\\Project\\GrandQuest Sister\\json-simple-1.1.1.jar
file.reference.json-simple-1.1.1.jar=C:\\Users\\Rikysamuel\\Downloads\\json-simple-1.1.1.jar
file.reference.org.json-20120521.jar=..\\server\\lib\\org.json-20120521.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.org.json-20120521.jar}:\
${libs.absolutelayout.classpath}:\
${file.reference.json-simple-1.1.1.jar-1}
${file.reference.json-simple-1.1.1.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
......
......@@ -21,16 +21,6 @@ public class LoginPanel extends javax.swing.JPanel {
* Creates new form LoginPanel
*/
public LoginPanel() {
// GrandQuest.host = "192.168.43.249";
// GrandQuest.port = 6789;
// GrandQuest.host = "localhost";
// GrandQuest.port = 8080;
GrandQuest.host = "167.205.32.46";
GrandQuest.port = 8025;
// GrandQuest.host = "localhost";
// GrandQuest.port = 8080;
// GrandQuest.host = "167.205.88.51";
// GrandQuest.port = 6789;
gq = new GrandQuest();
initComponents();
}
......@@ -178,8 +168,10 @@ public class LoginPanel extends javax.swing.JPanel {
}//GEN-LAST:event_usernameFormActionPerformed
private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed
GrandQuest.host = ipaddressForm.getText();
GrandQuest.port = Integer.valueOf(portForm.getText());
if(Request.connectToServer(GrandQuest.host,GrandQuest.port)){
String sentence = Request.loginJSON("abcdef", "abcdef").toString();
String sentence = Request.loginJSON(usernameForm.getText(), Request.encryptToMD5(String.valueOf(passwordForm.getPassword()))).toString();
Request.responseHandler(Request.send(sentence));
} else{
JOptionPane.showMessageDialog(null, "Can't Connect to the Server!", "Information", JOptionPane.ERROR_MESSAGE);
......@@ -198,7 +190,7 @@ public class LoginPanel extends javax.swing.JPanel {
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
if(Request.connectToServer(GrandQuest.host,GrandQuest.port)){
String sentence = Request.signUp(usernameForm.getText(),String.valueOf(passwordForm.getPassword())).toString();
String sentence = Request.signUp(usernameForm.getText(),Request.encryptToMD5(String.valueOf(passwordForm.getPassword()))).toString();
Request.responseHandler(Request.send(sentence));
}
......
......@@ -249,7 +249,7 @@ public class MapPanel extends javax.swing.JPanel {
} else{
if (countStatus==4){
countStatus = 0;
statusLabel.setText("moving");
statusLabel.setText("Moving");
} else{
countStatus++;
statusLabel.setText(statusLabel.getText()+".");
......
......@@ -19,8 +19,8 @@ public class Server {
try
{
int port = 8080;
String username = "abcdef";
String password = "abcdef";
String username = "abcdefgh";
String password = "e8dc4081b13434b45189a720b77b6818";
Random rand = new Random(); // untuk random posisi awal player
......
......@@ -12,6 +12,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
......@@ -477,13 +479,36 @@ public class Request {
return null;
}
public static void main(String argv[]) throws Exception{
if(connectToServer("localhost", 8080)){
String sentence = loginJSON("abc", "def").toString();
responseHandler(send(sentence));
/**
* method used to encrypt user data (password) before send it to the server
* @param str
* @return
*/
public static String encryptToMD5(String str) {
MessageDigest digester;
StringBuffer hexString = null;
try {
digester = MessageDigest.getInstance("MD5");
if (str == null || str.length() == 0) {
return null;
}
digester.update(str.getBytes());
byte[] hash = digester.digest();
hexString = new StringBuffer();
for (int i = 0; i < hash.length; i++) {
if ((0xff & hash[i]) < 0x10) {
hexString.append("0").append(Integer.toHexString((0xFF & hash[i])));
}
else {
hexString.append(Integer.toHexString(0xFF & hash[i]));
}
}
} catch (NoSuchAlgorithmException ex) {
System.err.println(ex);
}
System.out.println("respon status: " + findInResponses("status"));
System.out.println("respon description: " + findInResponses("description"));
return hexString.toString();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment