Skip to content

Commit 752fd92

Browse files
committed
Replacing genereatepassword with create pass
1 parent 39f066e commit 752fd92

File tree

2 files changed

+37
-95
lines changed

2 files changed

+37
-95
lines changed

sormas-api/src/main/java/de/symeda/sormas/api/utils/PasswordHelper.java

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import javax.validation.ValidationException;
2626

2727
import org.apache.commons.codec.binary.Hex;
28-
import java.util.Arrays;
2928

3029
public final class PasswordHelper {
3130

@@ -68,58 +67,6 @@ private PasswordHelper() {
6867
}
6968
}
7069

71-
public static String generatePasswordWithSpecialChars(int length) {
72-
// Combine the existing character set with special characters
73-
char[] combinedChars = Arrays.copyOf(PASSWORD_CHARS, PASSWORD_CHARS.length + 10);
74-
combinedChars[PASSWORD_CHARS.length] = '!';
75-
combinedChars[PASSWORD_CHARS.length + 1] = '@';
76-
combinedChars[PASSWORD_CHARS.length + 2] = '#';
77-
combinedChars[PASSWORD_CHARS.length + 3] = '$';
78-
combinedChars[PASSWORD_CHARS.length + 4] = '%';
79-
combinedChars[PASSWORD_CHARS.length + 5] = '^';
80-
combinedChars[PASSWORD_CHARS.length + 6] = '&';
81-
combinedChars[PASSWORD_CHARS.length + 7] = '*';
82-
combinedChars[PASSWORD_CHARS.length + 8] = '(';
83-
combinedChars[PASSWORD_CHARS.length + 9] = ')';
84-
85-
SecureRandom rnd = new SecureRandom();
86-
char[] chs = new char[length];
87-
88-
// Ensure at least one digit
89-
chs[0] = (char) ('2' + rnd.nextInt(8)); // 2-9
90-
91-
// Ensure at least one special character
92-
chs[1] = combinedChars[PASSWORD_CHARS.length + rnd.nextInt(10)];
93-
94-
// Ensure at least one uppercase letter
95-
chs[2] = (char) ('A' + rnd.nextInt(26));
96-
while (chs[2] == 'I' || chs[2] == 'O' || chs[2] == 'V') {
97-
chs[2] = (char) ('A' + rnd.nextInt(26));
98-
}
99-
100-
// Ensure at least one lowercase letter
101-
chs[3] = (char) ('a' + rnd.nextInt(26));
102-
while (chs[3] == 'l' || chs[3] == 'v') {
103-
chs[3] = (char) ('a' + rnd.nextInt(26));
104-
}
105-
106-
// Fill the rest of the password
107-
for (int i = 4; i < length; i++) {
108-
chs[i] = combinedChars[rnd.nextInt(combinedChars.length)];
109-
}
110-
111-
// Shuffle the password array to avoid predictable patterns
112-
for (int i = 0; i < chs.length; i++) {
113-
int randomIndex = rnd.nextInt(chs.length);
114-
char temp = chs[i];
115-
chs[i] = chs[randomIndex];
116-
chs[randomIndex] = temp;
117-
}
118-
119-
return new String(chs);
120-
}
121-
122-
12370
public static String createPass(final int length) {
12471

12572
SecureRandom rnd = new SecureRandom();

sormas-backend/src/main/java/de/symeda/sormas/backend/user/UserService.java

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,18 @@ public List<User> getAllByDistrictsAndUserRights(List<District> districts, Colle
183183
return em.createQuery(cq).getResultList();
184184
}
185185

186-
/**
187-
* Loads users filtered by combinable filter conditions.<br />
188-
* Condition combination if parameter is set:<br />
189-
* {@code ((regionUuids & districtUuids & filterByJurisdiction & userRoles) | includeSupervisors) & activeOnly}
190-
*
191-
* @see #createCurrentUserJurisdictionFilter(CriteriaBuilder, From)
192-
* @param regionUuids
193-
* @param districtUuids
194-
* @param filterByCurrentUserJurisdiction
195-
* @param activeOnly
196-
* @param userRights
197-
*/
186+
/**
187+
* Loads users filtered by combinable filter conditions.<br />
188+
* Condition combination if parameter is set:<br />
189+
* {@code ((regionUuids & districtUuids & filterByJurisdiction & userRoles) | includeSupervisors) & activeOnly}
190+
*
191+
* @param regionUuids
192+
* @param districtUuids
193+
* @param filterByCurrentUserJurisdiction
194+
* @param activeOnly
195+
* @param userRights
196+
* @see #createCurrentUserJurisdictionFilter(CriteriaBuilder, From)
197+
*/
198198
public List<UserReference> getUserReferences(List<String> regionUuids, List<String> districtUuids, boolean activeOnly, UserRight... userRights) {
199199

200200
return getUserReferences(regionUuids, districtUuids, null, activeOnly, userRights);
@@ -219,19 +219,19 @@ public List<UserReference> getUserReferences(
219219
return getUserReferences(regionUuids, districtUuids, communityUuids, activeOnly, limitedDisease, false, Arrays.asList(userRights));
220220
}
221221

222-
/**
223-
* Loads users filtered by combinable filter conditions.<br />
224-
* Condition combination if parameter is set:<br />
225-
* {@code ((regionUuids & districtUuids & communityUuids & filterByJurisdiction & userRoles) | includeSupervisors) & activeOnly}
226-
*
227-
* @see #createCurrentUserJurisdictionFilter(CriteriaBuilder, From)
228-
* @param regionUuids
229-
* @param districtUuids
230-
* @param communityUuids
231-
* @param filterByJurisdiction
232-
* @param activeOnly
233-
* @param userRights
234-
*/
222+
/**
223+
* Loads users filtered by combinable filter conditions.<br />
224+
* Condition combination if parameter is set:<br />
225+
* {@code ((regionUuids & districtUuids & communityUuids & filterByJurisdiction & userRoles) | includeSupervisors) & activeOnly}
226+
*
227+
* @param regionUuids
228+
* @param districtUuids
229+
* @param communityUuids
230+
* @param filterByJurisdiction
231+
* @param activeOnly
232+
* @param userRights
233+
* @see #createCurrentUserJurisdictionFilter(CriteriaBuilder, From)
234+
*/
235235
public List<UserReference> getUserReferences(
236236
List<String> regionUuids,
237237
List<String> districtUuids,
@@ -654,7 +654,7 @@ public static String setNewPassword(User user) {
654654
}
655655

656656
public String generatePassword() {
657-
return PasswordHelper.generatePasswordWithSpecialChars(12);
657+
return PasswordHelper.createPass(12);
658658
}
659659

660660
public String updatePassword(String userUuid, String password) {
@@ -763,7 +763,6 @@ public Long countByAssignedOfficer(User officer, UserRight userRights) {
763763
}
764764

765765
/**
766-
*
767766
* @param districts
768767
* @param userRight
769768
* @return Number of users with specified UserRight on district level
@@ -782,7 +781,6 @@ public Long countByDistricts(List<District> districts, UserRight userRight) {
782781
}
783782

784783
/**
785-
*
786784
* @param districts
787785
* @return Number of users with specified UserRight on community level
788786
*/
@@ -799,11 +797,10 @@ public Long countByCommunities(List<District> districts, UserRight userRight) {
799797
return em.createQuery(cq).getSingleResult();
800798
}
801799

802-
/**
803-
*
804-
* @param districts
805-
* @return Number of users with specified UserRight on health facility level
806-
*/
800+
/**
801+
* @param districts
802+
* @return Number of users with specified UserRight on health facility level
803+
*/
807804
public Long countByHealthFacilities(List<District> districts, UserRight userRight) {
808805

809806
CriteriaBuilder cb = em.getCriteriaBuilder();
@@ -817,11 +814,10 @@ public Long countByHealthFacilities(List<District> districts, UserRight userRigh
817814
return em.createQuery(cq).getSingleResult();
818815
}
819816

820-
/**
821-
*
822-
* @param districts
823-
* @return Number of users with specified UserRight on pointOfEntry level
824-
*/
817+
/**
818+
* @param districts
819+
* @return Number of users with specified UserRight on pointOfEntry level
820+
*/
825821
public Long countByPointOfEntries(List<District> districts, UserRight userRight) {
826822

827823
CriteriaBuilder cb = em.getCriteriaBuilder();
@@ -847,10 +843,9 @@ public boolean hasRegion(RegionReferenceDto regionReference) {
847843
return currentUser.getRegion().getUuid().equals(regionReference.getUuid());
848844
}
849845

850-
/**
851-
* @param root
852-
* root to {@link User} or {@link UserReference}.
853-
*/
846+
/**
847+
* @param root root to {@link User} or {@link UserReference}.
848+
*/
854849
private Predicate createDefaultFilter(CriteriaBuilder cb, From<?, ?> root) {
855850
return cb.isTrue(root.get(User.ACTIVE));
856851
}

0 commit comments

Comments
 (0)