Skip to content

Commit

Permalink
Merge pull request #57 from ccims/bugfix/negative_hashes
Browse files Browse the repository at this point in the history
fix bug in case of evil negative hashes
  • Loading branch information
nk-coding authored Jul 11, 2023
2 parents 26fa6db + 61c7d0c commit aa12a87
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package gropius.service.user

import org.springframework.stereotype.Service
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.pow

private const val SIZE = 36
Expand All @@ -27,7 +29,7 @@ class AvatarGenerationService {
* @return The avatar as Base64 encoded SVG data url
*/
fun generateAvatar(id: String): String {
val numFromName = id.hashCode()
val numFromName = max(abs(id.hashCode()), 0)
val range = colors.size
val preTranslateX = getUnit(numFromName, 10, 1)
val wrapperTranslateX = if (preTranslateX < 5) preTranslateX + SIZE / 9.0 else preTranslateX.toDouble()
Expand Down

0 comments on commit aa12a87

Please sign in to comment.