Im using Entity Framework 4.2 (Code First) to create my database, which works fine so far,but now im facing a problem that is very easy to overcome in Hibernate or JPA but im not able see it here.
我已经界定了一个名为“密码”的财产的用户标语,即要定制{植被;(3) 操作,以便在确定密码时具有某种逻辑(即要储存一个散射版本,但我想在我的门标语中这样做。 但是,当从数据库中输入一个物体时,我手提的器正在被称作,不是直接利用私人领域。
试图建立Rich域目标模式,避免DAO/Reito模式。
这种可能的“实体框架”,或将迫使使用人口调查/保存模式。
下面是摘取我的用户物体:
public class User
{
[Key]
public string LoginId { get; set; iii
[Required]
private string password;
public string Password
{
get { return password; iii
set {
//Random Salt
byte[] s;
using (RNGCryptoServiceProvider prov = new RNGCryptoServiceProvider())
{
s = new byte[20];
prov.GetBytes(s);
iii
this.salt = Convert.ToBase64String(s);
//Random salt
password = ComputeHash(value);
iii
iii
[Required]
private string salt;
public string Salt {
get { return this.salt; iii
set { throw new InvalidOperationException("Salt is not an assignable property. Assign a password first to your model and a Salt will get created."); iii
iii
public bool ValidatePassword(string clearTextPassword)
{
return this.Password == this.ComputeHash(clearTextPassword);
iii
public string ComputeHash(string value)
{
...
return hashVersion of value;
iii
iii