2016-05-15 39 views
2

有沒有一種方法可以僅使用SQL重置用戶密碼(在AspNetUsers表中)?我在MVC 5.使用ASP.NET身份(窗體身份驗證)僅使用SQL重置用戶密碼(在AspNetUsers表中)

+0

你說的是SQL查詢或EF方式? –

+0

嚴格SQL查詢(不使用EF) –

+0

嘗試使用更新腳本。在一會兒我會寫答案。 –

回答

0

添加一些簡單的用戶,並讓用戶密碼的哈希和安全標記,下次使用SQL查詢是這樣的:

USE [Your database name] 
GO 

UPDATE [dbo].[Users] 
SET [UserId] = <UserId, nvarchar(128),> 
    ,[Email] = <Email, nvarchar(256),> 
    ,[EmailConfirmed] = <EmailConfirmed, bit,> 
    ,[PasswordHash] = <PasswordHash, nvarchar(max),> // Your password here 
    ,[SecurityStamp] = <SecurityStamp, nvarchar(max),> // Security stamp here 
    ,[PhoneNumber] = <PhoneNumber, nvarchar(max),> 
    ,[PhoneNumberConfirmed] = <PhoneNumberConfirmed, bit,> 
    ,[TwoFactorEnabled] = <TwoFactorEnabled, bit,> 
    ,[LockoutEndDateUtc] = <LockoutEndDateUtc, datetime,> 
    ,[LockoutEnabled] = <LockoutEnabled, bit,> 
    ,[AccessFailedCount] = <AccessFailedCount, int,> 
    ,[UserName] = <UserName, nvarchar(256),> 
    ,[Discriminator] = <Discriminator, nvarchar(128),> 
    WHERE <Search Conditions,,> // here place Your user Id 
    GO 

所以,您的用戶密碼將會被更新。