I am using the following code to generate an encrypted password:
class DuplicateHandler<T> implements AsyncCallback<User> {
public void onFailure(Throwable ex) {
Window.alert("RPC call failed.");
}
public void onSuccess(User result) {
User u = result;
if (u == null) {
String pw_hash = BCrypt.hashpw(passwordTextBoxEmail.getText(),
BCrypt.gensalt());
System.out.println("Hashed password lenth is: " + pw_hash.length());
AsyncCallback<User> callback = new CreationHandler<User>();
rpc.createUser(textBoxAccount.getText(), pw_hash, null, null, null,
callback);
} else {
Window
.alert("Username already in use. Please select another Username.");
}
}
}
And I get the following error:
[DEBUG] [org.AwardTracker.AwardTracker] - Validating units:
[INFO] [org.AwardTracker.AwardTracker] - Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[INFO] [org.AwardTracker.AwardTracker] - Module org.AwardTracker.AwardTracker has been loaded
[ERROR] [org.AwardTracker.AwardTracker] - Errors in 'file:/C:/Users/Glyndwr/Eclipse/Workspace/AwardTracker/src/org/AwardTracker/client/BCrypt.java'
[ERROR] [org.AwardTracker.AwardTracker] - Line 535: Cannot invoke clone() on the array type int[]
[ERROR] [org.AwardTracker.AwardTracker] - Line 536: Cannot invoke clone() on the array type int[]
[ERROR] [org.AwardTracker.AwardTracker] - Line 609: Cannot invoke clone() on the array type int[]
[ERROR] [org.AwardTracker.AwardTracker] - Line 706: No source code is available for type java.security.SecureRandom; did you forget to inherit a required module?
[ERROR] [org.AwardTracker.AwardTracker] - Uncaught exception escaped
15:10:39.817 [ERROR] [org.AwardTracker.AwardTracker] Uncaught exception escaped
java.lang.Error: Unresolved compilation problem:
Cannot invoke clone() on the array type int[]
at org.AwardTracker.client.BCrypt.crypt_raw(BCrypt.java:609)
at org.AwardTracker.client.BCrypt.hashpw(BCrypt.java:682)
at org.AwardTracker.client.CreateAccountView$1$DuplicateHandler.onSuccess(CreateAccountView.java:103)
at org.AwardTracker.client.CreateAccountView$1$DuplicateHandler.onSuccess(CreateAccountView.java:1)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)
As per the documentation I have included BCrypt.java and the single line to call BCypt and return a value. I have not modified BCrypt.java.
Any help would be appreciated.
Regards,
Glyn
I wanted to do the same thing in GWT, that is, I wanted to use BCrypt on the client side; unfortunately, the java.security package has not been ported to GWT, which is why you cannot use the java.security.SecureRandom class on the client side. One solution would be to port that class yourself. My decision was to use BCrypt on the server side, and to rely on secure sockets (SSL) to protect the passwords sent from the client to the server. The packages that have been made available on the client side in GWT can be found here: JRE Emulation Reference