We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f97e756 commit 168f3f1Copy full SHA for 168f3f1
common/src/main/scala/org/example/security/TokenGenerator.scala
@@ -1,11 +1,26 @@
1
package org.example.security
2
3
+import java.security.SecureRandom
4
+
5
/**
6
* Generates string tokens.
7
*/
-final object TokenGenerator {
8
+object TokenGenerator {
9
+ val LENGTH = 32
10
11
+ private[this] val ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
12
+ private[this] val RANDOM = new SecureRandom
13
14
15
* Generates a string token.
16
- def generateToken = "ABCD1234"
17
+ def generateToken: String = {
18
+ val builder = new StringBuilder
19
20
+ for (i <- 1 to LENGTH) {
21
+ builder.append(ALPHABET.charAt(RANDOM.nextInt(ALPHABET.length)))
22
+ }
23
24
+ builder.toString()
25
26
}
0 commit comments