Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4004


Ignore:
Timestamp:
07/06/10 17:14:42 (14 years ago)
Author:
bfarka
Message:

fixed min passwordlength test #1046

Location:
branches/HeuristicLab.Services.Authentication Prototype
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs

    r4003 r4004  
    2424    private int pMaxInvalidPasswordAttempts;
    2525    private int pPasswordAttemptWindow;
    26     private int pMinRequiredPasswordLength;
     26    private int pMinRequiredPasswordLength = 5;
    2727    private MembershipPasswordFormat pPasswordFormat = MembershipPasswordFormat.Clear;
    2828
     
    134134          return false;
    135135        }
     136
     137        if (newPassword.Length < MinRequiredPasswordLength) {
     138          return false;
     139        }
     140
    136141        try {
    137142          // try to get user
     
    144149          }
    145150          return false;
    146          
    147          
     151
     152
    148153        }
    149154        catch (Exception) {
     
    184189            return null;
    185190          }
     191          if (password.Length < MinRequiredPasswordLength) {
     192            status = MembershipCreateStatus.InvalidPassword;
     193            return null;
     194          }
    186195
    187196          // create new user
     
    271280      }
    272281    }
    273 
     282    /// <summary>
     283    /// not jet implemented returns 0 as default
     284    /// </summary>
     285    /// <returns></returns>
    274286    public override int GetNumberOfUsersOnline() {
    275       throw new NotImplementedException();
     287      return 0;
    276288    }
    277289
     
    299311    }
    300312
    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      }
    353355    }
    354356
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs

    r4003 r4004  
    123123    public void MinRequiredPasswordLengthTest() {
    124124      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"));
    128133    }
    129134
     
    334339      actual = target.GetNumberOfUsersOnline();
    335340      Assert.AreEqual(expected, actual);
    336       Assert.Inconclusive("Verify the correctness of this test method.");
    337341    }
    338342
Note: See TracChangeset for help on using the changeset viewer.