Skip to content

Commit

Permalink
Use secure random generator. (#5941)
Browse files Browse the repository at this point in the history
  • Loading branch information
henning-gerhardt authored Feb 23, 2024
1 parent 4fa7db4 commit 2969b18
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@

package org.kitodo.selenium.testframework.generators;

import java.security.SecureRandom;

import org.apache.commons.lang3.RandomStringUtils;
import org.kitodo.data.database.beans.User;

public class UserGenerator {

private static final SecureRandom secureRandom = new SecureRandom();

/**
* Create user with random name, surname, login and password.
*
* @return Created user.
*/
public static User generateUser() {
String suffix = generateRandomString(5);

Expand All @@ -30,7 +39,15 @@ public static User generateUser() {
return user;
}

/**
* Create a random string with a defined length.
*
* @param length How long the to be created string should be
* @return Created string with random values.
*/
private static String generateRandomString(int length) {
return RandomStringUtils.random(length, true, true);
// RandomStringUtils is using a non-secure random generator by default
// call random method with all parameters to set a secure random generator
return RandomStringUtils.random(length, 0, 0, true, true, null, secureRandom);
}
}

0 comments on commit 2969b18

Please sign in to comment.