开发者

Password Field with Asp.Net Dynamic Data

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜