SQL 创建 .Net Membership Provider 用户
我有一个在我的数据库中创建用户的 SQL 脚本。 它使用.Net 成员资格存储过程。
此时效果很好。
唯一的问题是密码是保存的明文。我应该在这里更改什么以使其加盐/加密(不知道这里使用什么术语)
GO
DECLARE @return_value int,
@UserId uniqueidentifier
EXEC @return_value = [dbo].[aspnet_Membership_CreateUser]
@ApplicationName = N'Theater',
@UserName = N'sam.sosa',
@Password = N'mypassword',
@PasswordSalt = N'eyhKDP858wdrYHbBmFoQ6DXzFE1FB+RDP4ULrpoZXt6f',
@Email = N'[email protected]',
@PasswordQuestion = N'Whats your favorite color',
@PasswordAnswer = N'Fusia',
@IsApproved = 1,
@CurrentTimeUtc = '2010-03-03',
@CreateDate = '2010-03-03',
@UniqueEmail = 1,
@PasswordFormat = 0,
@UserId = @UserId OUTPUT
SELECT @UserId as N'@UserId'
SELECT 'Return Value' = @return_value
GO
谢谢!
I have a SQL script that creates users in in my database.
It uses the .Net membership stored procs.
At this point it works fine.
The only issue is that the passwords are saved clear text. What should I change here to they are salted/encrypted (Not sure what term to use here)
GO
DECLARE @return_value int,
@UserId uniqueidentifier
EXEC @return_value = [dbo].[aspnet_Membership_CreateUser]
@ApplicationName = N'Theater',
@UserName = N'sam.sosa',
@Password = N'mypassword',
@PasswordSalt = N'eyhKDP858wdrYHbBmFoQ6DXzFE1FB+RDP4ULrpoZXt6f',
@Email = N'[email protected]',
@PasswordQuestion = N'Whats your favorite color',
@PasswordAnswer = N'Fusia',
@IsApproved = 1,
@CurrentTimeUtc = '2010-03-03',
@CreateDate = '2010-03-03',
@UniqueEmail = 1,
@PasswordFormat = 0,
@UserId = @UserId OUTPUT
SELECT @UserId as N'@UserId'
SELECT 'Return Value' = @return_value
GO
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在“哈希”密码存储模式的底层,它只是简单地计算:
SHA1(盐 + 密码)
Salt 以 Base64 编码存储,因此必须在与 (Unicode) 密码连接之前对其进行解码。最后将结果进行Base64编码存储。
以下(可怕的)SQL 将输出一个适当编码的值,该值可以替换您当前拥有的“mypassword”。您还必须将 @PasswordFormat 设置为 1 以指示密码以散列形式存储。
Under the hood it looks like for the "Hashed" password storage mode, it simply calculates:
SHA1(Salt + Password)
The Salt is stored Base64 encoded, so it must be decoded prior to being concatenated with the (Unicode) password. Finally, the result is Base64 encoded for storage.
The following (horrible) SQL will output a suitably encoded value which can be substituted in place of the "mypassword" that you currently have. You must also set @PasswordFormat to 1 to indicate that the password is stored hashed.