19-10-2008 22:58:17
Kỳ quặc cực kỳ luôn.
Chúng ta đăng nhập username và password, hệ thống sẽ thực hiện như sau:
AspNetMembershipProvider (DNN)
System.Web.Security.Membership.ValidateUser(username, password); (MS)
System.Web.Security.MembershipProvider.ValidateUser(username, password); (MS)
System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(username, password) (MS)
trong thằng cuối cùng nó gọi stored procedure
SqlCommand command = new SqlCommand("dbo.aspnet_Membership_GetPasswordWithFormat", connection.Connection);
command.CommandTimeout = this.CommandTimeout;
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(this.CreateInputParam("@ApplicationName", SqlDbType.NVarChar, this.ApplicationName));
command.Parameters.Add(this.CreateInputParam("@UserName", SqlDbType.NVarChar, username));
command.Parameters.Add(this.CreateInputParam("@UpdateLastLoginActivityDate", SqlDbType.Bit, updateLastLoginActivityDate));
command.Parameters.Add(this.CreateInputParam("@CurrentTimeUtc", SqlDbType.DateTime, DateTime.UtcNow));
parameter = new SqlParameter("@ReturnValue", SqlDbType.Int);
Kỳ lạ là làm sao code của MS, mà thằng DNN biết tất cả những cái đó và viết 1 cái stored có tên như vậy trong DB của mình.
Nó như sau:
------------------------------
CREATE PROCEDURE dbo.aspnet_Membership_GetPasswordWithFormat
@ApplicationName nvarchar(256),
@UserName nvarchar(256),
@UpdateLastLoginActivityDate bit,
@CurrentTimeUtc datetime
AS
BEGIN
DECLARE @IsLockedOut bit
DECLARE @UserId uniqueidentifier
DECLARE @Password nvarchar(128)
DECLARE @PasswordSalt nvarchar(128)
DECLARE @PasswordFormat int
DECLARE @FailedPasswordAttemptCount int
DECLARE @FailedPasswordAnswerAttemptCount int
DECLARE @IsApproved bit
DECLARE @LastActivityDate datetime
DECLARE @LastLoginDate datetime
SELECT @UserId = NULL
SELECT @UserId = u.UserId, @IsLockedOut = m.IsLockedOut, @Password=Password, @PasswordFormat=PasswordFormat,
@PasswordSalt=PasswordSalt, @FailedPasswordAttemptCount=FailedPasswordAttemptCount,
@FailedPasswordAnswerAttemptCount=FailedPasswordAnswerAttemptCount, @IsApproved=IsApproved,
@LastActivityDate = LastActivityDate, @LastLoginDate = LastLoginDate
FROM dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.aspnet_Membership m
WHERE LOWER(@ApplicationName) = a.LoweredApplicationName AND
u.ApplicationId = a.ApplicationId AND
u.UserId = m.UserId AND
LOWER(@UserName) = u.LoweredUserName
IF (@UserId IS NULL)
RETURN 1
IF (@IsLockedOut = 1)
RETURN 99
SELECT @Password, @PasswordFormat, @PasswordSalt, @FailedPasswordAttemptCount,
@FailedPasswordAnswerAttemptCount, @IsApproved, @LastLoginDate, @LastActivityDate
IF (@UpdateLastLoginActivityDate = 1 AND @IsApproved = 1)
BEGIN
UPDATE dbo.aspnet_Membership
SET LastLoginDate = @CurrentTimeUtc
WHERE UserId = @UserId
UPDATE dbo.aspnet_Users
SET LastActivityDate = @CurrentTimeUtc
WHERE @UserId = UserId
END
RETURN 0
END
GO
-----------------------------