Đang chuẩn bị liên kết để tải về tài liệu:
NET Domain-Driven Design with C#P roblem – Design – Solution phần 10
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Phương pháp này bắt đầu bằng cách đầu tiên xác nhận đối số của nó, và sau đó gọi phương pháp ValidateUser tĩnh. public static void ValidatePassword (string password) {SecurityHelper.CheckParameter (mật khẩu, đúng, sai, sai, 0, "mật khẩu"); ứng dụng ứng dụng = | Chapter 11 The Client Membership System The ChangePassword Method This is the first of several methods that will be delegating any heavy lifting to the ClientMembershipService class which I will look at later in the chapter. public void ChangePassword string oldPassword string newPassword SecurityHelper.CheckPasswordParameter oldPassword 0 oldPassword SecurityHelper.CheckPasswordParameter newPassword 0 newPassword User.ValidatePassword newPassword ClientMembershipService.ChangePassword this.UserName oldPassword newPassword This method starts out by first validating its arguments and then calls the static ValidateUser method. public static void ValidatePassword string password SecurityHelper.CheckParameter password true false false 0 password Application application ClientMembershipService.Application if password.Length application.MinRequiredPasswordLength throw new ArgumentException Password too short password int count 0 for int i 0 i password.Length i if char.IsLetterOrDigit password i count if count application.MinRequiredNonAlphanumericCharacters throw new ArgumentException Password needs more non alphanumeric chars password if application.PasswordStrengthRegularExpression.Length 0 if Regex.IsMatch password application.PasswordStrengthRegularExpression throw new ArgumentException Password does not match regular expression password 364 Chapter 11 The Client Membership System if password.Length application.MaxPasswordSize throw new ArgumentException Password too long password I made this method static so I would be able to centralize this logic in the domain in order for it to be reused from a Client Membership Provider. This method does a very exhaustive job of validating the password. It ends up conducting five different tests on the password parameter 1. It first checks to see whether the parameter is null via the Checkparameter method shown previously. 2. The next check is to make sure that the password meets the minimum length requirements of the Client .