本文介绍了在ASP.NET Identity中为数据库中的旧用户填充SecurityStamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与ASP.NET Identity一起使用的旧数据库.为了使用身份功能,每个用户在数据库中都需要一个SecurityStamp值.

I have a legacy database that I am using with ASP.NET Identity. In order to use the Identity functions a SecurityStamp value is required in the database for each user.

在与此相关的其他问题中,有人提到该值可以是任何随机值,例如EG是一个随机整数",但这听起来不对!!

Some have mentioned in other questions relating to this that the value can be 'any random value, EG a random int' but that doesn't sound right to me!?

我使用以下代码在数据库中创建了一个新用户:

I created a new user in the database using this code:

IdentityResult result = await UserManager.CreateAsync(user, model.Password);

,并使用以下值填充它:cea9a659-e965-4e76-8203-ed1c79491fa7

and it populated it with the following value: cea9a659-e965-4e76-8203-ed1c79491fa7

对我来说,这似乎比随机的int更安全"的值,尤其是当它称为SecurityStamp时,似乎应该以相同的方式填充数据库中的所有用户.

That seems like a more 'secure' value to me than a random int, especially when it's called the SecurityStamp, it seems like it should be populated in the same manner for all users in my database.

如何正确填充用户数据库的SecurityStamp值?

How can I populate the SecurityStamp values for my Users database, properly?

推荐答案

默认情况下,安全戳是GUID,而且我还没有任何修改它的方法.因此,如果您想为所有现有用户填充该值,只需运行sql:

Security Stamp by default is GUID and I have not seen any way to modify it. So you if you want to populate that value for all existing users just run sql:

update AspNetUsers
set SecurityStamp = NEWID()
where SecurityStamp is null

这篇关于在ASP.NET Identity中为数据库中的旧用户填充SecurityStamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 01:06