News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How could I register a user using MySQL/Java?

Started by Tetrahydrocannabinol, December 29, 2014, 05:29:17 PM

Previous topic - Next topic

Arantor

NOW() returns a datetime, not an integer Unixish timestamp. You should use UNIX_TIMESTAMP() instead.

This still doesn't fix the other stuff that registerMember does, though... like updating the settings table with various things, but we'll get to that in a bit. I still really don't like the fact you're doing this like this because it also means you can't upgrade to SMF 2.1 without changing your server code.

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Tetrahydrocannabinol

#22
Quote from: Arantor on January 04, 2015, 07:43:08 PM
NOW() returns a datetime, not an integer Unixish timestamp. You should use UNIX_TIMESTAMP() instead.

This still doesn't fix the other stuff that registerMember does, though... like updating the settings table with various things, but we'll get to that in a bit. I still really don't like the fact you're doing this like this because it also means you can't upgrade to SMF 2.1 without changing your server code.

It's still giving the same error when using the UNIX_TIMESTAMP().
For now, I can just put a 0 as a placeholder so I can fix the rest of the system.. Then come back to this part..
As you said, there's other stuff to do.

Edit: I replaced the UNIX_TIMESTAMP() with (int) (new Date().getTime()/1000) and now the dates are registering correctly.

I went on my forums and checked the member list and the account was listed. it was also able to login to the forums..
What parts am I missing for the registration? I mean, besides making the forums auth the account via email, which I don't really need atm..

Arantor

QuoteIt's still giving the same error when using the UNIX_TIMESTAMP().

Funny, it works perfectly when I do that. I also find it funny that the query worked correctly when you copy/pasted it because as was quite clear, NOW() didn't work, so I don't see why the query should have worked when you copy/pasted it before. They are MySQL functions, not Java ones.

QuoteWhat parts am I missing for the registration?

Updating the various stats, mostly.

Quotebesides making the forums auth the account via email

SMF does that out of the box.

Tetrahydrocannabinol

Quote from: Arantor on January 05, 2015, 08:15:58 AM
QuoteIt's still giving the same error when using the UNIX_TIMESTAMP().

Funny, it works perfectly when I do that. I also find it funny that the query worked correctly when you copy/pasted it because as was quite clear, NOW() didn't work, so I don't see why the query should have worked when you copy/pasted it before. They are MySQL functions, not Java ones.
Yeah, that's what was confusing me. I wasn't understanding why they wouldn't work because of that.. But I guess Java's date class will have to do for now :3

QuoteUpdating the various stats, mostly.
Such as the total members and etc?

QuoteSMF does that out of the box.
Yeah I believe that I made the accounts skip that part by changing a value or two in the sql I use.

Arantor

If the login process sees an email address, it tries to find a username for that email address internally and then tries to perform the login. The only reason that might not work is if you didn't set up the account properly (either unhashed password or no password salt) in which case conventional login is also messed up.

Tetrahydrocannabinol

Quote from: Arantor on January 05, 2015, 05:28:31 PM
If the login process sees an email address, it tries to find a username for that email address internally and then tries to perform the login. The only reason that might not work is if you didn't set up the account properly (either unhashed password or no password salt) in which case conventional login is also messed up.
I think I've got the correct password salt for pass, which from what I read was the username. And the server hashes the password before sending it to the database.

Arantor

If you have that done correctly (and I don't know, since I don't see the contents of getSHA1 listed), there is no reason why login via email wouldn't work properly. Just remember: when you log in with email/password, you do not pass the password in hashed the way you can for username.

Tetrahydrocannabinol

Quote from: Arantor on January 05, 2015, 08:30:09 PM
If you have that done correctly (and I don't know, since I don't see the contents of getSHA1 listed), there is no reason why login via email wouldn't work properly. Just remember: when you log in with email/password, you do not pass the password in hashed the way you can for username.

The SHAGenerator class wasn't made by me. but this is the getSHA1 method
public static String getSHA1(String passwordToHash, String salt) {
String generatedPassword = null;
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(salt.getBytes());
byte[] bytes = md.digest(passwordToHash.getBytes());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16)
.substring(1));
}
generatedPassword = sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return generatedPassword;
}


And the login does work.. I believe.

Arantor

SMF works by taking the username, lower-casing it, concatenating the password and SHA1'ing the result, I could be wrong but I don't think the way you're injecting the salt into it is correct for that methodology.

Tetrahydrocannabinol

Quote from: Arantor on January 05, 2015, 08:40:40 PM
SMF works by taking the username, lower-casing it, concatenating the password and SHA1'ing the result, I could be wrong but I don't think the way you're injecting the salt into it is correct for that methodology.
Wouldn't SMF throw an error if a user created using that SQL tried to login? Because I made a test account and it logged in.

Arantor

Yes, it would - if it was incorrect. I'm only guessing because I don't know *that* much Java but it looked wrong to me is all.

Tetrahydrocannabinol

Quote from: Arantor on January 05, 2015, 08:48:59 PM
Yes, it would - if it was incorrect. I'm only guessing because I don't know *that* much Java but it looked wrong to me is all.
I don't know everything about Java either.. I got that class from a tutorial somewhere, so I can only hope it's correct.
I tried looking online for it for reference and can't seem to find it :L

Are other stats and etc that need to be updated, updated by SQL queries?

Tetrahydrocannabinol

I finished up the final touches of it today. I got the statistics updating and everything too.
:3

Advertisement: