@@ -221,6 +221,38 @@ public static boolean login(PlayerDetails player, String username, String passwo
221
221
return success ;
222
222
}
223
223
224
+ public static boolean login (String username , String password ) {
225
+ boolean success = false ;
226
+
227
+ Connection sqlConnection = null ;
228
+ PreparedStatement preparedStatement = null ;
229
+ ResultSet resultSet = null ;
230
+
231
+ try {
232
+ sqlConnection = Storage .getStorage ().getConnection ();
233
+ preparedStatement = Storage .getStorage ().prepare ("SELECT id, password FROM users WHERE username = ? LIMIT 1" , sqlConnection );
234
+ preparedStatement .setString (1 , username );
235
+ resultSet = preparedStatement .executeQuery ();
236
+
237
+ if (resultSet .next ()) {
238
+ byte [] hashedPassword = (resultSet .getString ("password" ) + '\0' ).getBytes (StandardCharsets .UTF_8 );
239
+ byte [] pass = password .getBytes (StandardCharsets .UTF_8 );
240
+
241
+ PwHash .Native pwHash = (PwHash .Native ) Kepler .getLibSodium ();
242
+ success = pwHash .cryptoPwHashStrVerify (hashedPassword , pass , pass .length );
243
+ }
244
+
245
+ } catch (Exception e ) {
246
+ Storage .logError (e );
247
+ } finally {
248
+ Storage .closeSilently (resultSet );
249
+ Storage .closeSilently (preparedStatement );
250
+ Storage .closeSilently (sqlConnection );
251
+ }
252
+
253
+ return success ;
254
+ }
255
+
224
256
/**
225
257
* Clear SSO ticket
226
258
* Protects against replay attacks
@@ -441,6 +473,86 @@ public static void saveMotto(PlayerDetails details) {
441
473
}
442
474
}
443
475
476
+ public static void saveReceiveMail (PlayerDetails details ) {
477
+ Connection sqlConnection = null ;
478
+ PreparedStatement preparedStatement = null ;
479
+
480
+ try {
481
+ sqlConnection = Storage .getStorage ().getConnection ();
482
+ preparedStatement = Storage .getStorage ().prepare ("UPDATE users SET receive_email = ? WHERE id = ?" , sqlConnection );
483
+ preparedStatement .setBoolean (1 , details .isReceiveNews ());
484
+ preparedStatement .setInt (2 , details .getId ());
485
+ preparedStatement .execute ();
486
+
487
+ } catch (Exception e ) {
488
+ Storage .logError (e );
489
+ } finally {
490
+ Storage .closeSilently (preparedStatement );
491
+ Storage .closeSilently (sqlConnection );
492
+ }
493
+ }
494
+
495
+ /**
496
+ * Update details.
497
+ */
498
+ public static void savePassword (int userId , String password ) {
499
+ Connection sqlConnection = null ;
500
+ PreparedStatement preparedStatement = null ;
501
+
502
+ try {
503
+ sqlConnection = Storage .getStorage ().getConnection ();
504
+ preparedStatement = Storage .getStorage ().prepare ("UPDATE users SET password = ? WHERE id = ?" , sqlConnection );
505
+ preparedStatement .setString (1 , password );
506
+ preparedStatement .setInt (2 , userId );
507
+ preparedStatement .execute ();
508
+
509
+ } catch (Exception e ) {
510
+ Storage .logError (e );
511
+ } finally {
512
+ Storage .closeSilently (preparedStatement );
513
+ Storage .closeSilently (sqlConnection );
514
+ }
515
+ }
516
+
517
+ public static void saveBirthday (int userId , String birthday ) {
518
+ Connection sqlConnection = null ;
519
+ PreparedStatement preparedStatement = null ;
520
+
521
+ try {
522
+ sqlConnection = Storage .getStorage ().getConnection ();
523
+ preparedStatement = Storage .getStorage ().prepare ("UPDATE users SET birthday = ? WHERE id = ?" , sqlConnection );
524
+ preparedStatement .setString (1 , birthday );
525
+ preparedStatement .setInt (2 , userId );
526
+ preparedStatement .execute ();
527
+
528
+ } catch (Exception e ) {
529
+ Storage .logError (e );
530
+ } finally {
531
+ Storage .closeSilently (preparedStatement );
532
+ Storage .closeSilently (sqlConnection );
533
+ }
534
+ }
535
+
536
+ public static void saveEmail (int userId , String email ) {
537
+ Connection sqlConnection = null ;
538
+ PreparedStatement preparedStatement = null ;
539
+
540
+ try {
541
+ sqlConnection = Storage .getStorage ().getConnection ();
542
+ preparedStatement = Storage .getStorage ().prepare ("UPDATE users SET email = ? WHERE id = ?" , sqlConnection );
543
+ preparedStatement .setString (1 , email );
544
+ preparedStatement .setInt (2 , userId );
545
+ preparedStatement .execute ();
546
+
547
+ } catch (Exception e ) {
548
+ Storage .logError (e );
549
+ } finally {
550
+ Storage .closeSilently (preparedStatement );
551
+ Storage .closeSilently (sqlConnection );
552
+ }
553
+ }
554
+
555
+
444
556
/**
445
557
* Update details.
446
558
*
@@ -482,10 +594,10 @@ private static void fill(PlayerDetails details, ResultSet row) throws SQLExcepti
482
594
483
595
details .fill (row .getInt ("id" ), row .getString ("username" ), row .getString ("figure" ),
484
596
row .getString ("pool_figure" ), row .getInt ("credits" ), row .getString ("motto" ),
485
- row .getString ("console_motto" ), row .getString ("sex" ), row .getInt ( "tickets " ),
486
- row .getInt ("film " ), row .getInt ("rank " ), row .getLong ( "last_online " ),
487
- row .getLong ("club_subscribed " ), row .getLong ("club_expiration " ), row .getLong ("club_gift_due " ),
488
- row .getString ("badge" ),
597
+ row .getString ("console_motto" ), row .getString ("sex" ), row .getString ( "birthday " ),
598
+ row .getInt ("tickets " ), row .getInt ("film " ), row .getInt ( "rank " ),
599
+ row .getLong ("last_online " ), row .getLong ("club_subscribed " ), row .getLong ("club_expiration " ),
600
+ row .getLong ( "club_gift_due" ), row . getString ("badge" ),
489
601
row .getBoolean ("badge_active" ), row .getBoolean ("allow_stalking" ),
490
602
row .getBoolean ("allow_friend_requests" ), row .getBoolean ("sound_enabled" ),
491
603
row .getBoolean ("tutorial_finished" ), row .getInt ("battleball_points" ),
0 commit comments