Secure login - Java server

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

JohnnyD
Posts: 128
Joined: 29 Oct 2007, 22:13

Secure login - Java server

Postby JohnnyD » 17 Sep 2008, 10:10

I can't find any MD5 functionality in the Java SFS API. Is it only present in the AS server API? I don't think MD5 is built into Java, are you aware of any free Java implementations?

By the way, why does the secureLogin example use a 3rd-party MD5 tool on the client side, when you must already have your own AS MD5 tool for the server?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Sep 2008, 09:31

User this

Code: Select all

import it.gotoandplay.smartfoxserver.crypto;
...
...
MD5 md5 = MD5.instance();
String hash = md5.getHash("MyStringGoesHere");

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
JohnnyD
Posts: 128
Joined: 29 Oct 2007, 22:13

Postby JohnnyD » 18 Sep 2008, 09:47

Thanks, I actually came across that last night. Why doesn't your 8.9 example use this instead of 3rd party JS code... you could then discuss how MD5, SHA-1/224/256 are all available in that package.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Sep 2008, 11:12

As far as I can remember the 8.9 tutorials uses 3rd party code on the client side, not server side.
Lapo

--

gotoAndPlay()

...addicted to flash games
JohnnyD
Posts: 128
Joined: 29 Oct 2007, 22:13

Postby JohnnyD » 18 Sep 2008, 11:43

Yes. Why?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Sep 2008, 15:05

Because the client must calculate the MD5 on its side not receive the hash from the server side.
Lapo

--

gotoAndPlay()

...addicted to flash games
JohnnyD
Posts: 128
Joined: 29 Oct 2007, 22:13

Postby JohnnyD » 18 Sep 2008, 15:20

No I mean why does the client use the 3rd-part MD5 instead of the built in com.adobe.crypto classes?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Sep 2008, 15:30

Because the demo is in Actionscript 2.0 :)
If you use AS3 in your project then you can use those, of course.
Lapo

--

gotoAndPlay()

...addicted to flash games
JohnnyD
Posts: 128
Joined: 29 Oct 2007, 22:13

Postby JohnnyD » 18 Sep 2008, 15:32

Ohhhhh. Right, makes sense now, thanks for clearing this up.

Do most users still use AS2.0 rather than AS3.0?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Sep 2008, 15:39

Nice question... difficult to say. A lot of customers are now using Actionscript 3, but still AS 2 has a large user base.

Anyways, at the time of the creation of that example AS3 didn't even exist :D
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
thecreatrix
Posts: 19
Joined: 20 Aug 2008, 02:32
Contact:

Postby thecreatrix » 19 Sep 2008, 14:01

How do we get the server instance from Java? For example, in the tutorial it refers to the _server variable, but what's the equivalent in Java?

Thanks!

Edit: I see that SmartFoxServer.getInstance() returns a reference to the server, but I still cannot find any login calls (I also looked in AbstractExtension and ExtensionHelper).

It is mentioned in this tutorial that we can login a user (_server.loginUser()) after we authenticate, but the example is ActionScript, and I can't find the equivalent in Java. (SFS Pro 1.6.3)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 22 Sep 2008, 07:51

ExtensionHelper is the main entry point to the API.
All you have to do is keep a reference to it in your code:

Code: Select all

ExtensionHelper api = ExtensionHelper.getInstance()

In the javadoc you find all the details about each method.

Additionally in your Server/javaExtensions/ folder you find examples of java extensions with their sources.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
thecreatrix
Posts: 19
Joined: 20 Aug 2008, 02:32
Contact:

Postby thecreatrix » 22 Sep 2008, 11:48

Ok, so ExtensionHelper.canLogin() is what we use to login a user? In the tutorial it uses .loginUser() so that's what I was looking for (and it doesn't exist).

Thanks!
User avatar
thecreatrix
Posts: 19
Joined: 20 Aug 2008, 02:32
Contact:

Postby thecreatrix » 22 Sep 2008, 17:16

I apologize for being thick headed here, but I'm still trying to get this custom handleInternalEvent() stuff to work. :oops:

When I call ExtensionHelper.instance().canLogin() to log a user in after authenticating credentials, the server doesn't seem to send any of the events that normally would be sent to the client upon default login. For example, my client no longer receives the SFSEvent.onLogIn event now that I am using the custom login in my extension. (I have verified that the user is indeed logging in successfully on the server side.)

Do we have to "manually" tell the server to fire these events? If so, is there documentation about how to do that?

Thanks!

Edit: I realize, also, that it may be that we need to not rely on the login events when using this custom method. That's fine, but I just want to know if that's the case or if I'm missing something. :)
User avatar
thecreatrix
Posts: 19
Joined: 20 Aug 2008, 02:32
Contact:

Postby thecreatrix » 22 Sep 2008, 19:43

I have now managed to implement this successfully by calling ExtensionHelper.sendRoomList() after the login succeeds. That fires the event to the client so it can handle the onRoomListUpdate event.

It would be nice if the tutorial got an update with a bit more information on how the login process changes when implemented using an internal event handler. Other than my initial confusion, though, SFS makes it very easy.

Cheers.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 29 guests