storing the hashed password serverside to use it later
storing the hashed password serverside to use it later
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
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
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:
In other words, after a successfull login you can do something like this:
Code: Select all
theUser.properties.put("hash", theHash)
problems
Hi, i've done what u said using:
newUser.properties.put("validation", md5);
but i got an error:
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
the code
Hi lapo thx for help, here it is
[/quote]
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);
}
mitticooooo
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:
could be replaced by this:
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);
yes
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
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.
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
Raketspel
soon i will post my properties variables...
Last edited by mittico on 03 Jan 2008, 16:54, edited 1 time in total.
mitticooooo
Hi lapo, this is the newUser Variables I copied at runtime
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
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
Return to “SmartFoxServer 1.x Discussions and Help”
Who is online
Users browsing this forum: No registered users and 69 guests