Entity Framework: Saving of Password as SecureString
In my User class I have the password w开发者_如何学JAVAhich is SecureString. To save the password, I have added the UserPassword property.
Sample code:
internal partial class User
{
public string ID { get; set; }
private string _password;
public SecureString Password
{
set { _password = SomePasswordHashing(value.ToString); }
}
public string UserPassword
{
get { return _password; }
set { _password = value; }
}
}
For the saving/retrieving of the UserPassword, does this property need to be public?
Is there a way not to load a UserPassword property (for instance when searching for the users, I would want to exclude loading all users' passwords)?
For the saving/retrieving of the UserPassword, does this property need to be public?
Yes. EF-Code first needs properties to be public.
Is there a way not to load a UserPassword property (for instance when searching for the users, I would want to exclude loading all users' passwords)?
You can transform the results when searching to exclude passwords
var users = db.Users.Where(/* */).Select(u => new User{Name = u.Name});
Or use a DTO class which does not have a password property and return the DTO classes instead of the model object.
精彩评论