|
37 | 37 | import com.google.firebase.auth.UserRecord;
|
38 | 38 | import com.google.firebase.auth.UserRecord.CreateRequest;
|
39 | 39 | import com.google.firebase.auth.UserRecord.UpdateRequest;
|
| 40 | +import com.google.firebase.auth.hash.Argon2; |
| 41 | +import com.google.firebase.auth.hash.Argon2.Argon2HashType; |
| 42 | +import com.google.firebase.auth.hash.Argon2.Argon2Version; |
40 | 43 | import com.google.firebase.auth.hash.Bcrypt;
|
41 | 44 | import com.google.firebase.auth.hash.HmacSha256;
|
42 | 45 | import com.google.firebase.auth.hash.Pbkdf2Sha256;
|
@@ -588,6 +591,35 @@ public void importWithScrypt() {
|
588 | 591 | // [END import_with_scrypt]
|
589 | 592 | }
|
590 | 593 |
|
| 594 | + public void importWithArgon2() { |
| 595 | + // [START import_with_argon2] |
| 596 | + try { |
| 597 | + List<ImportUserRecord> users = Collections.singletonList(ImportUserRecord.builder() |
| 598 | + .setUid("some-uid") |
| 599 | + |
| 600 | + .setPasswordHash("password-hash".getBytes()) |
| 601 | + .setPasswordSalt("salt".getBytes()) |
| 602 | + .build()); |
| 603 | + UserImportOptions options = UserImportOptions.withHash( |
| 604 | + Argon2.builder() |
| 605 | + .setHashLengthBytes(512) |
| 606 | + .setHashType(Argon2HashType.ARGON2_ID) |
| 607 | + .setParallelism(8) |
| 608 | + .setIterations(16) |
| 609 | + .setMemoryCostKib(2048) |
| 610 | + .setVersion(Argon2Version.VERSION_10) |
| 611 | + .setAssociatedData("associated-data".getBytes()) |
| 612 | + .build()); |
| 613 | + UserImportResult result = FirebaseAuth.getInstance().importUsers(users, options); |
| 614 | + for (ErrorInfo indexedError : result.getErrors()) { |
| 615 | + System.out.println("Failed to import user: " + indexedError.getReason()); |
| 616 | + } |
| 617 | + } catch (FirebaseAuthException e) { |
| 618 | + System.out.println("Error importing users: " + e.getMessage()); |
| 619 | + } |
| 620 | + // [END import_with_argon2] |
| 621 | + } |
| 622 | + |
591 | 623 | public void importWithoutPassword() {
|
592 | 624 | // [START import_without_password]
|
593 | 625 | try {
|
|
0 commit comments