我有一個應用程序的一些很老的(醜陋的)的代碼,我建立了一個幾年前。這幾乎是它使用aspnet_Membership_UnlockUser存儲過程與設置在gridrow,被鎖定的用戶的用戶名的關鍵delete命令GridView控件的黑客攻擊了。我甚至沒有使用C#。這是我有:
<asp:Label runat="server" ID="LblLockedUsers" Text="Locked Out Users:" />
<asp:SqlDataSource ID="SqlLockedUsers" runat="server" ConnectionString='<%$ ConnectionStrings:myConnString %>'
SelectCommand="selLockedOutUsers" SelectCommandType="StoredProcedure" DeleteCommand="aspnet_Membership_UnlockUser"
DeleteCommandType="StoredProcedure" />
<asp:GridView ID="GvLockedUsers" runat="server" AllowPaging="True" PageSize="5" AutoGenerateColumns="False"
DataKeyNames="UserName" DataSourceID="SqlLockedUsers" AllowSorting="True" GridLines="None"
Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LnkUnlock" CommandArgument='<%# Eval("UserName") %>' CommandName="Delete" runat="server">Unlock</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="True" SortExpression="UserName" />
<asp:CheckBoxField DataField="IsLockedOut" HeaderText="Locked Out" ReadOnly="True" SortExpression="IsLockedOut" />
<asp:BoundField DataField="LastLockoutDate" HeaderText="Last Lockout" SortExpression="LastLockoutDate" ReadOnly="True" />
<asp:BoundField DataField="failedPasswordAttemptCount" HeaderText="Failed Password Attempts" SortExpression="failedPasswordAttemptCount" ReadOnly="True" />
</Columns>
<EmptyDataTemplate>
No users are locked out at this time.
</EmptyDataTemplate>
</asp:GridView>
這是我寫的gridview使用的舊存儲過程。這一切都可以做得更好,但這是我當時所做的,它運作良好。
CREATE PROCEDURE [dbo].[selLockedOutUsers]
AS
SELECT
m.ApplicationId as applicationId,
a.ApplicationName as applicationName,
m.UserId as userId,
u.UserName as UserName,
m.IsLockedOut as isLockedOut,
m.LastLoginDate as lastLoginDate,
m.LastLockoutDate as lastLockoutDate,
m.FailedPasswordAttemptCount as failedPasswordAttemptCount
FROM
aspnet_Membership m
JOIN aspnet_Users u ON m.UserId = u.UserId
JOIN aspnet_Applications a ON m.ApplicationId = a.ApplicationId
WHERE
m.IsLockedOut = '1'
這裏是我修改的aspnet_Membership_UnlockUser存儲過程。正如你所看到的,我刪除了應用程序名稱參數,只需手動將其設置在proc中即可。這樣我只需要通過用戶名作爲參數。
ALTER PROCEDURE [dbo].[aspnet_Membership_UnlockUser]
[email protected] nvarchar(256), --replaced with '/'
@UserName nvarchar(256)
AS
BEGIN
DECLARE @UserId uniqueidentifier
SELECT @UserId = NULL
SELECT @UserId = u.UserId
FROM dbo.aspnet_Users u, dbo.aspnet_Applications a, dbo.aspnet_Membership m
WHERE LoweredUserName = LOWER(@UserName) AND
u.ApplicationId = a.ApplicationId AND
LOWER('/') = a.LoweredApplicationName AND
u.UserId = m.UserId
IF (@UserId IS NULL)
RETURN 1
UPDATE dbo.aspnet_Membership
SET IsLockedOut = 0,
FailedPasswordAttemptCount = 0,
FailedPasswordAttemptWindowStart = CONVERT(datetime, '17540101', 112),
FailedPasswordAnswerAttemptCount = 0,
FailedPasswordAnswerAttemptWindowStart = CONVERT(datetime, '17540101', 112),
LastLockoutDate = CONVERT(datetime, '17540101', 112)
WHERE @UserId = UserId
RETURN 0
END
+1質量數據的會員經理控制 – 2010-12-04 11:48:56