views:

25

answers:

2

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?

A: 

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);
           }
       }
   }
}
Jedi Master Spooky
+1  A: 

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

Wizzard
I am suing your password Field TEmplate, any Idea How I modified that to do this?
Jedi Master Spooky