feat!: implemented multigame support (#34)
Reviewed-on: #34 Co-authored-by: Janis <janis.e.20@gmx.de> Co-committed-by: Janis <janis.e.20@gmx.de>
This commit is contained in:
29
knockoutwhistweb/app/util/GameUtil.scala
Normal file
29
knockoutwhistweb/app/util/GameUtil.scala
Normal file
@@ -0,0 +1,29 @@
|
||||
package util
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
object GameUtil {
|
||||
|
||||
private val CharPool: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
private val CodeLength: Int = 6
|
||||
private val MaxRepetition: Int = 2
|
||||
private val random = new Random()
|
||||
|
||||
def generateCode(): String = {
|
||||
val freq = Array.fill(CharPool.length)(0)
|
||||
val code = new StringBuilder(CodeLength)
|
||||
|
||||
for (_ <- 0 until CodeLength) {
|
||||
var index = random.nextInt(CharPool.length)
|
||||
// Pick a new character if it's already used twice
|
||||
while (freq(index) >= MaxRepetition) {
|
||||
index = random.nextInt(CharPool.length)
|
||||
}
|
||||
freq(index) += 1
|
||||
code.append(CharPool.charAt(index))
|
||||
}
|
||||
|
||||
code.toString()
|
||||
}
|
||||
|
||||
}
|
||||
23
knockoutwhistweb/app/util/UserHash.scala
Normal file
23
knockoutwhistweb/app/util/UserHash.scala
Normal file
@@ -0,0 +1,23 @@
|
||||
package util
|
||||
|
||||
import de.mkammerer.argon2.Argon2Factory
|
||||
import de.mkammerer.argon2.Argon2Factory.Argon2Types
|
||||
import model.users.User
|
||||
|
||||
object UserHash {
|
||||
private val ITERATIONS: Int = 3
|
||||
private val MEMORY: Int = 32_768
|
||||
private val PARALLELISM: Int = 1
|
||||
private val SALT_LENGTH: Int = 32
|
||||
private val HASH_LENGTH: Int = 64
|
||||
private val ARGON_2 = Argon2Factory.create(Argon2Types.ARGON2id, SALT_LENGTH, HASH_LENGTH)
|
||||
|
||||
def hashPW(password: String): String = {
|
||||
ARGON_2.hash(ITERATIONS, MEMORY, PARALLELISM, password.toCharArray)
|
||||
}
|
||||
|
||||
def verifyUser(password: String, user: User): Boolean = {
|
||||
ARGON_2.verify(user.passwordHash, password.toCharArray)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,6 +29,6 @@ object WebUIUtils {
|
||||
case Three => "3"
|
||||
case Two => "2"
|
||||
}
|
||||
views.html.output.card.apply(f"images/cards/$cv$s.png")(card.toString)
|
||||
views.html.render.card.apply(f"images/cards/$cv$s.png")(card.toString)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user