storing the hashed password serverside to use it later

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

amnesya
Posts: 18
Joined: 10 Dec 2007, 21:54

storing the hashed password serverside to use it later

Postby amnesya » 27 Dec 2007, 01:01

When I use custom login, where can I retrieve the hashed passwd in the server on later actions ?

for example I need to validate the action performed in an extension from that client that logged in regularly before.

this is to avoid database connection any time I must validate the client to do important things.

thanks
User avatar
Lapo
Site Admin
Posts: 21691
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 27 Dec 2007, 08:03

Each User object has a properties Map object attached to it where you can store any data related to the user's state.

In other words, after a successfull login you can do something like this:

Code: Select all

theUser.properties.put("hash", theHash)
Lapo
--
gotoAndPlay()
...addicted to flash games
amnesya
Posts: 18
Joined: 10 Dec 2007, 21:54

Postby amnesya » 27 Dec 2007, 09:53

is it safe ?

can someone else access that data ?

or only the server can ?

thanks 4 help
User avatar
Lapo
Site Admin
Posts: 21691
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 27 Dec 2007, 10:17

the data is kept on the server side only, so it's secured
Lapo

--

gotoAndPlay()

...addicted to flash games
mittico
Posts: 36
Joined: 08 Dec 2007, 13:00
Location: Santena
Contact:

problems

Postby mittico » 27 Dec 2007, 13:40

Hi, i've done what u said using:
newUser.properties.put("validation", md5);
but i got an error:

15:02:24.546 - [ INFO ] > Server is up and running!
Exception in thread "SystemHandler-1" java.lang.NoSuchFieldError: properties
at game.Application.handleInternalEvent(Application.java:506)
at it.gotoandplay.smartfoxserver.controllers.MessageHandler.dispatchEven
t(MessageHandler.java:141)
at it.gotoandplay.smartfoxserver.controllers.SystemHandler.handleLoginRe
quest(SystemHandler.java:439)
at it.gotoandplay.smartfoxserver.controllers.SystemHandler.processEvent(
SystemHandler.java:194)
at it.gotoandplay.smartfoxserver.controllers.SystemHandler.run(SystemHan
dler.java:143)
at java.lang.Thread.run(Unknown Source)
mitticooooo
User avatar
Lapo
Site Admin
Posts: 21691
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 27 Dec 2007, 22:44

please show the snippet of code that you're using
Lapo

--

gotoAndPlay()

...addicted to flash games
mittico
Posts: 36
Joined: 08 Dec 2007, 13:00
Location: Santena
Contact:

the code

Postby mittico » 27 Dec 2007, 22:57

Hi lapo thx for help, here it is

Code: Select all

      //funzione che controlla il login dell'utente
      if (ieo.getEventName().equalsIgnoreCase("loginRequest")) {

         boolean ok = false;
         String error = "";
         String nick =  ieo.getParam("nick");
         String pword = ieo.getParam("pass");
         SocketChannel chan = (SocketChannel) ieo.getObject("chan");
         ActionscriptObject response = new ActionscriptObject();

         User newUser= null;
         SecretKeyGenerator keyMaker = SecretKeyGenerator.instance();

         // Get the secret key of this channel
         String key = helper.getSecretKey(chan);

         String pass = "****";
         String md5 = MD5.instance().getHash(key + pass);



         LinkedList lscList = new LinkedList();
         lscList.add(chan);


         if (!md5.equals(pword))
                   {
                           response.put("err","invalid login");
                           response.put("_cmd", "logKO");
                   }
                   else {

         try {

            newUser = (helper.canLogin(nick, pword, chan, this.__zoneName));

            response.put("_cmd", "logOK");
            response.put("id", String.valueOf(newUser.getUserId()));
            response.put("name", newUser.getName());

            ok = true;
         }
         catch (LoginException le)
         {
            this.trace("Could not login user: " + nick);

            response.put("_cmd", "logKO");
            response.put("err", le.getMessage());
         }

         //}
         String res1 = response.getString("_cmd");


            if (res1.equalsIgnoreCase("logOk")) {
               newUser.properties.put("validation", md5);
            }

         sendResponse(response, -1, null, lscList);

         helper.sendRoomList(chan);
      }
[/quote]
mitticooooo
mittico
Posts: 36
Joined: 08 Dec 2007, 13:00
Location: Santena
Contact:

news?

Postby mittico » 02 Jan 2008, 21:17

lapo any news about this problem?
mitticooooo
User avatar
Lapo
Site Admin
Posts: 21691
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 02 Jan 2008, 21:28

Are you sure that your code compiles correctly??
The noSuchField error should definitely be caught at compile time, unless you have some server version mismatch going on.

On a side note, this code:

Code: Select all

String res1 = response.getString("_cmd");

if (res1.equalsIgnoreCase("logOk")) {
   newUser.properties.put("validation", md5);
}

could be replaced by this:

Code: Select all

if (newUser != null)
   newUser.properties.put("validation",md5);
Lapo

--

gotoAndPlay()

...addicted to flash games
mittico
Posts: 36
Joined: 08 Dec 2007, 13:00
Location: Santena
Contact:

yes

Postby mittico » 02 Jan 2008, 22:37

Yes, I'm sure I'm using correct code, i got no compile errors :( i only got a warning about not parameterized hashmap, but this should be normal, or not?
mitticooooo
User avatar
potmo
Posts: 154
Joined: 02 Feb 2007, 14:28
Location: Stockholm Sweden
Contact:

Postby potmo » 03 Jan 2008, 08:14

the properties field is an <Object, Object> HashMap.
Since all java object inheritage from java.lang.Object you cant know whats in it so when you get() stuff from the properties field you must typecast the objects

In the case you have a String as value in your HashMap you have to:

String myString = (String)(sfUser.properties.get("hash"));

The best would if you could parameterize the properties field at declatarion like this:

HashMap<String, String> properties = new HashMap<String,String>();

but since the declatarion is already done you will have to live with this.
The nice part of this is that the properties field is generic so the smartfox-crew havent decided for you what to put in your properties.

A workaround (i dont know why you should but.. Maybe someone more Javaish could give us some infor on performence and stuff on this) is to make your own hashMap with properties with the user as key and a nested HashMap with <String, String> (if thats what you want).

HashMap<user, HashMap<String,String>> myProperties = new HashMap<User, HashMap<String,String>>();
myPropertis.put(user, new HashMap<String,String>());

(I havent tested this code but i guess it will work).

Hope i shed some light on this to someone.
Nisse Bergman
Raketspel
User avatar
Lapo
Site Admin
Posts: 21691
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 03 Jan 2008, 08:16

the warnings are ok but it's not clear why the "properties" field would disappear at runtime while there's no compile-time error.
Try checking the type of newUser at runtime.
Lapo

--

gotoAndPlay()

...addicted to flash games
mittico
Posts: 36
Joined: 08 Dec 2007, 13:00
Location: Santena
Contact:

Postby mittico » 03 Jan 2008, 16:36

soon i will post my properties variables...
Last edited by mittico on 03 Jan 2008, 16:54, edited 1 time in total.
mitticooooo
mittico
Posts: 36
Joined: 08 Dec 2007, 13:00
Location: Santena
Contact:

Postby mittico » 03 Jan 2008, 16:37

Hi lapo, this is the newUser Variables I copied at runtime

newUser User (id=92)
admin false
badwordsWarningCounter 0
bbSessionId null
blueBoxed false
buddyListChanged false
buddyVariables ConcurrentHashMap<K,V> (id=94)
channel SocketChannelImpl (id=53)
dbId 0
droppedPackets 0
floodCounter 0
floodWarningsCounter 0
ipAddr "62.11.1.244"
isBeingKicked false
isChallenging false
isPlayer false
isPlaying false
lastMessage null
lastMessageTime 1199380242687
loginTime 1199380242687
markedForRemoval false
moderator false
name "squid"
playerIndex 0
playerIndexes HashMap<K,V> (id=100)
properties HashMap<K,V> (id=102)
entrySet null
keySet null
loadFactor 0.75
modCount 0
size 0
table HashMap$Entry<K,V>[16] (id=105)
[0] null
[1] null
[2] null
[3] null
[4] null
[5] null
[6] null
[7] null
[8] null
[9] null
[10] null
[11] null
[12] null
[13] null
[14] null
[15] null
threshold 12
values null
repeatedMsgCounter 0
roomsConnected LinkedList<E> (id=103)
roomsCreated LinkedList<E> (id=104)
uid 0
userPrivileges 0
userVars HashMap<K,V> (id=140)
zone "provagioco"


hope to solve this problem soon :(
pls help me i really don't understand what the problem could be
i putted in red the details of the properties variable
mitticooooo
mittico
Posts: 36
Joined: 08 Dec 2007, 13:00
Location: Santena
Contact:

news?

Postby mittico » 04 Jan 2008, 09:47

no news eh? I think this should be moved to bugs...
mitticooooo

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 31 guests