Revision 112:8338347effdc
src/main/java/my/com/upass/MinimalUPassController.java | ||
---|---|---|
171 | 171 |
final String userPlainPassword = userHashedPassword; |
172 | 172 |
userHashedPassword = PasswordController.sha256(userPlainPassword); |
173 | 173 |
} |
174 |
rc = pc.verifyUserAlias(userAlias); |
|
174 |
rc = pc.verifyUserAlias(userAlias, new Integer(0));
|
|
175 | 175 |
// if useralias is valid then continue else return error |
176 | 176 |
if (rc == MinimalConstants.ERR_SUCCESS) { |
177 | 177 |
rc = pc.generatePassword(userHashedPassword, false); |
src/main/java/my/com/upass/MinimalUPassControllerV2.java | ||
---|---|---|
240 | 240 |
|
241 | 241 |
int rc; |
242 | 242 |
CreateUserService.ReturnBundle creationResult = |
243 |
createUserService.addUser(user, txSession, checkPassword); |
|
243 |
createUserService.addUser(user, appId, txSession, checkPassword);
|
|
244 | 244 |
|
245 | 245 |
rc = creationResult.getCode(); |
246 | 246 |
if (rc == MinimalConstants.ERR_SUCCESS && appId != null) { |
src/main/java/my/com/upass/services/CreateUserService.java | ||
---|---|---|
61 | 61 |
|
62 | 62 |
public ReturnBundle addUser( |
63 | 63 |
String userAlias, int userType, String userDesc, |
64 |
String userHashedPassword, int userState, Session txSession, boolean usePassword) { |
|
64 |
String userHashedPassword, int userState, Integer targetAppId, |
|
65 |
Session txSession, boolean usePassword) { |
|
65 | 66 |
|
66 | 67 |
final ReturnBundle ret = new ReturnBundle(); |
67 | 68 |
ret.code = MinimalConstants.ERR_SYSTEM_NOT_READY; |
... | ... | |
91 | 92 |
ub.setPdateCreated(new Date()); |
92 | 93 |
// ub.setApplicationId(new Integer(applicationId)); //has been moved to UserAppAccess |
93 | 94 |
|
94 |
PasswordController pc = MinimalUPassFactory.getPasswordController(ub,
|
|
95 |
upc.getConfigurationsMap()); |
|
96 |
ret.code = pc.verifyUserAlias(userAlias); |
|
95 |
PasswordController pc = MinimalUPassFactory.getPasswordController( |
|
96 |
ub, upc.getConfigurationsMap());
|
|
97 |
ret.code = pc.verifyUserAlias(userAlias, targetAppId);
|
|
97 | 98 |
|
98 | 99 |
if (ret.code != MinimalConstants.ERR_SUCCESS) { |
99 | 100 |
return ret; |
... | ... | |
139 | 140 |
|
140 | 141 |
public ReturnBundle addUser( |
141 | 142 |
String userAlias, int userType, String userDesc, |
142 |
String userHashedPassword, int userState, Session txSession) { |
|
143 |
String userHashedPassword, int userState, Integer targetAppId, Session txSession) {
|
|
143 | 144 |
|
144 | 145 |
return addUser( |
145 |
userAlias, userType, userDesc, userHashedPassword, userState, txSession, true); |
|
146 |
userAlias, userType, userDesc, userHashedPassword, userState, |
|
147 |
targetAppId, txSession, true); |
|
146 | 148 |
} |
147 | 149 |
|
148 | 150 |
public int addUser( |
149 | 151 |
String userAlias, int userType, String userDesc, |
150 | 152 |
String userHashedPassword, int userState, int appId) { |
151 | 153 |
|
152 |
ReturnBundle ret = addUser(userAlias, userType, userDesc, userHashedPassword, userState, null); |
|
154 |
ReturnBundle ret = addUser( |
|
155 |
userAlias, userType, userDesc, userHashedPassword, |
|
156 |
userState, new Integer(appId), null); |
|
153 | 157 |
|
154 | 158 |
int rc = ret.code; |
155 | 159 |
if (rc == MinimalConstants.ERR_SUCCESS |
... | ... | |
167 | 171 |
} |
168 | 172 |
|
169 | 173 |
public ReturnBundle addUser( |
170 |
MinimalUserBean user, Session txSession, |
|
171 |
boolean userPassword) { |
|
174 |
MinimalUserBean user, Integer targetAppId, Session txSession, boolean userPassword) { |
|
172 | 175 |
|
173 |
ReturnBundle ret = addUser(user.getUserAlias(), user.getUserType(),
|
|
174 |
user.getDescription(), user.getHashedPassword(),
|
|
175 |
user.getPstate(), txSession, userPassword);
|
|
176 |
ReturnBundle ret = addUser( |
|
177 |
user.getUserAlias(), user.getUserType(), user.getDescription(),
|
|
178 |
user.getHashedPassword(), user.getPstate(), targetAppId, txSession, userPassword);
|
|
176 | 179 |
|
177 | 180 |
if (ret.userId != null) |
178 | 181 |
user.setUserID(ret.userId.longValue()); |
179 |
|
|
182 |
|
|
180 | 183 |
return ret; |
181 | 184 |
} |
182 | 185 |
} |
src/main/java/my/com/upass/spassword/PasswordController.java | ||
---|---|---|
106 | 106 |
// Public Verify User Alias |
107 | 107 |
// 20120627 - Return ERR_INVALID_USERALIAS if the given name is not matching the pattern |
108 | 108 |
// ///////////////////////////////////////////////////////////////////// |
109 |
public int verifyUserAlias(String userAlias) { |
|
109 |
public int verifyUserAlias(String userAlias, Integer appId) {
|
|
110 | 110 |
logger.info("userAlias=" + userAlias + " Regular Expression=" + _USERNAME_PATTERN); |
111 |
if (patternValidator(userAlias, getConfigBean().getUserNameValidPattern())) { |
|
111 |
if (patternValidator(userAlias, getConfigBean(appId).getUserNameValidPattern())) {
|
|
112 | 112 |
return MinimalConstants.ERR_SUCCESS; |
113 | 113 |
} |
114 | 114 |
|
... | ... | |
627 | 627 |
|
628 | 628 |
public static void main(String[] args) { |
629 | 629 |
PasswordController pc = new PasswordController(); |
630 |
|
|
630 |
|
|
631 | 631 |
Map userPassMap = new LinkedHashMap(); |
632 |
|
|
633 |
if(args.length == 2) { |
|
634 |
userPassMap.put( args[0], args[1]);
|
|
635 |
|
|
632 |
|
|
633 |
if (args.length == 2) {
|
|
634 |
userPassMap.put(args[0], args[1]); |
|
635 |
|
|
636 | 636 |
} else { |
637 | 637 |
String password = "aaaa7777"; |
638 | 638 |
System.out.println(pc.patternValidator(password, "(?=.*\\w).{8,12}")); |
639 | 639 |
// String cipherText1 = pass.sha1("wakakaka", "aaaa0000"); |
640 | 640 |
// System.out.println(cipherText1); |
641 | 641 |
// System.out.println("------------"); |
642 |
|
|
643 |
userPassMap.put( "root", "P@ssw0rd");
|
|
644 |
userPassMap.put( "UpassAdmin", "password");
|
|
645 |
userPassMap.put( "ibuser1", "Passw0rd");
|
|
646 |
userPassMap.put( "ibuser2", "Passw0rd");
|
|
647 |
userPassMap.put( "ibuser3", "Passw0rd");
|
|
648 |
userPassMap.put( "ibuser4", "Passw0rd");
|
|
649 |
userPassMap.put( "ibuser5", "Passw0rd");
|
|
650 |
userPassMap.put( "administrator", "Mss@dm1n");
|
|
642 |
|
|
643 |
userPassMap.put("root", "P@ssw0rd"); |
|
644 |
userPassMap.put("UpassAdmin", "password"); |
|
645 |
userPassMap.put("ibuser1", "Passw0rd"); |
|
646 |
userPassMap.put("ibuser2", "Passw0rd"); |
|
647 |
userPassMap.put("ibuser3", "Passw0rd"); |
|
648 |
userPassMap.put("ibuser4", "Passw0rd"); |
|
649 |
userPassMap.put("ibuser5", "Passw0rd"); |
|
650 |
userPassMap.put("administrator", "Mss@dm1n"); |
|
651 | 651 |
} |
652 | 652 |
|
653 | 653 |
for (Iterator iterator = userPassMap.keySet().iterator(); iterator.hasNext();) { |
654 | 654 |
String username = (String) iterator.next(); |
655 | 655 |
String password = (String) userPassMap.get(username); |
656 | 656 |
String hashedPassword = PasswordController.sha256(password); |
657 |
System.out.println("Plain username/password: " + username + "/" + password
|
|
658 |
+ "\n\t Hashed password (H2): " + hashedPassword
|
|
657 |
System.out.println("Plain username/password: " + username + "/" + password |
|
658 |
+ "\n\t Hashed password (H2): " + hashedPassword |
|
659 | 659 |
+ "\n\t Hashed username+H2 (H5): " + PasswordController.sha256(username, hashedPassword)); |
660 | 660 |
} |
661 | 661 |
} |
Also available in: Unified diff