开发者

Password Field with Asp.Net Dynamic Data

开发者 https://www.devze.com 2023-01-07 16:08 出处:网络
I have a User table that I want to use with Dynamic Data. The Problem is that I have the Password Field that I need to encrypt using MD5.开发者_开发问答 I am Using Entity Framework, How I do this?On a

I have a User table that I want to use with Dynamic Data. The Problem is that I have the Password Field that I need to encrypt using MD5.开发者_开发问答 I am Using Entity Framework, How I do this?


On alternate idea would be to create a custom FieldTemplate (use UIHint to override the field field template) to encrypt this field.


I found this solution, but If anyone has a better Idea, let me know

 public partial class SigecRendicionesEntities
{
   partial void OnContextCreated()
   {
       // Register the handler for the SavingChanges event.
       this.SavingChanges
           += new EventHandler(context_SavingChanges);
   }

   // SavingChanges event handler.
   private static void context_SavingChanges(object sender, EventArgs e)
   {
       // Validate the state of each entity in the context
       // before SaveChanges can succeed.
       foreach (ObjectStateEntry entry in
           ((ObjectContext)sender).ObjectStateManager.GetObjectStateEntries(
           EntityState.Added | EntityState.Modified))
       {
           // Find an object state entry for a SalesOrderHeader object. 
           if (entry.Entity.GetType() == typeof(Usuario))
           {
               Usuario usr = entry.Entity as Usuario;



               string hashProvider = "MD5CryptoServiceProvider";
               usr.Clave = Cryptographer.CreateHash(hashProvider, usr.Clave);
           }
       }
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消