Changeset 4004
- Timestamp:
- 07/06/10 17:14:42 (15 years ago)
- Location:
- branches/HeuristicLab.Services.Authentication Prototype
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs
r4003 r4004 24 24 private int pMaxInvalidPasswordAttempts; 25 25 private int pPasswordAttemptWindow; 26 private int pMinRequiredPasswordLength ;26 private int pMinRequiredPasswordLength = 5; 27 27 private MembershipPasswordFormat pPasswordFormat = MembershipPasswordFormat.Clear; 28 28 … … 134 134 return false; 135 135 } 136 137 if (newPassword.Length < MinRequiredPasswordLength) { 138 return false; 139 } 140 136 141 try { 137 142 // try to get user … … 144 149 } 145 150 return false; 146 147 151 152 148 153 } 149 154 catch (Exception) { … … 184 189 return null; 185 190 } 191 if (password.Length < MinRequiredPasswordLength) { 192 status = MembershipCreateStatus.InvalidPassword; 193 return null; 194 } 186 195 187 196 // create new user … … 271 280 } 272 281 } 273 282 /// <summary> 283 /// not jet implemented returns 0 as default 284 /// </summary> 285 /// <returns></returns> 274 286 public override int GetNumberOfUsersOnline() { 275 throw new NotImplementedException();287 return 0; 276 288 } 277 289 … … 299 311 } 300 312 301 public bool LockUser(string userName) 302 { 303 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) 304 { 305 // check database connection 306 if (db == null) 307 { 308 return false; 309 } 310 try 311 { 312 // try to get user 313 HeuristicLabUser u = 314 db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == userName); 315 316 // unlock user 317 u.Locked = true; 318 db.SubmitChanges(); 319 return true; 320 } 321 catch (Exception) 322 { 323 return false; 324 } 325 } 326 } 327 328 public override bool UnlockUser(string userName) 329 { 330 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) 331 { 332 // check database connection 333 if (db == null) 334 { 335 return false; 336 } 337 try 338 { 339 // try to get user 340 HeuristicLabUser u = 341 db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == userName); 342 343 // unlock user 344 u.Locked = false; 345 db.SubmitChanges(); 346 return true; 347 } 348 catch (Exception) 349 { 350 return false; 351 } 352 } 313 public bool LockUser(string userName) { 314 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 315 // check database connection 316 if (db == null) { 317 return false; 318 } 319 try { 320 // try to get user 321 HeuristicLabUser u = 322 db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == userName); 323 324 // unlock user 325 u.Locked = true; 326 db.SubmitChanges(); 327 return true; 328 } 329 catch (Exception) { 330 return false; 331 } 332 } 333 } 334 335 public override bool UnlockUser(string userName) { 336 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 337 // check database connection 338 if (db == null) { 339 return false; 340 } 341 try { 342 // try to get user 343 HeuristicLabUser u = 344 db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == userName); 345 346 // unlock user 347 u.Locked = false; 348 db.SubmitChanges(); 349 return true; 350 } 351 catch (Exception) { 352 return false; 353 } 354 } 353 355 } 354 356 -
branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs
r4003 r4004 123 123 public void MinRequiredPasswordLengthTest() { 124 124 MembershipProvider target = Membership.Provider; // TODO: Initialize to an appropriate value 125 int actual; 126 actual = target.MinRequiredPasswordLength; 127 Assert.Inconclusive("Verify the correctness of this test method."); 125 126 MembershipCreateStatus status; 127 target.CreateUser("username", "", "mail", "question", "answer", true, null,out status); 128 Assert.AreEqual(status, MembershipCreateStatus.InvalidPassword); 129 target.CreateUser("username", "testusername", "mail", "question", "answer", true, null, out status); 130 Assert.AreEqual(status, MembershipCreateStatus.Success); 131 Assert.IsFalse(target.ChangePassword("username", "testusername", "")); 132 Assert.IsTrue(target.ChangePassword("username", "testusername", "foofoofoo")); 128 133 } 129 134 … … 334 339 actual = target.GetNumberOfUsersOnline(); 335 340 Assert.AreEqual(expected, actual); 336 Assert.Inconclusive("Verify the correctness of this test method.");337 341 } 338 342
Note: See TracChangeset
for help on using the changeset viewer.