Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passwords
Message
From
27/01/2005 10:21:19
 
 
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Miscellaneous
Thread ID:
00981126
Message ID:
00981202
Views:
33
Einar,

UPDATE ... hold on, this reply isn't totally accurate (I've been thinking some more about it), but I don't have time to post right now. Give me an hour or two and I'll have a better answer to follow.

I assume that you're trying to use Cathi's solution that she posted for you some time ago. You say the problem with using dataRow.HasVersion(DataRowVersion.Proposed) is that it's returning false. This sounds very strange, especially if the dataRow.RowState == DataRowState.Modified ... it *has* to have a Proposed row, but maybe what you should try is this modified version of Cathi's solution:
protected override bool HookPreSave(DataTable dt) {
   foreach (DataRow dataRow in dt.Rows)
   {
     if (dataRow.RowState == DataRowState.Added)
     {
       dataRow["Password"] = Encrypt(dataRow["Password"].ToString());
     }
     else if (dataRow.RowState == DataRowState.Modified)
     {
       If dataRow("Password", DataRowVersion.Current) Is dataRow(1, DataRowVersion.Proposed)
       {
           // Only encrypt the password if it has been changed
       }
     }
   }
   return base.HookPreSave(dt);
}
I haven't tested this, I just merged your code with Cathi's example. Have you tried something like this?

~~Bonnie


>Hi,
>
>Using our own encryption algorithm, I need to encrypt a user's password if it is a new user, or and existing user has modified their password. To do this I am overriding the mmUser's HookPreSave(DataTable dt) method. The problem is that I cannot figure out if the password column has a modified value or not (I can find out if the row is modified but not which column has modified values). Unfortunately I cannot decrypt an encrypted password (one way encryption algorithm) and I only want to encrypt if the password is new or modified (else I will double encrypt an already encrypted password).
>
>The problem is that dataRow.HasVersion(DataRowVersion.Proposed) returns False for a modified row so I can't check if it is the password column that has been modified or just some other user data. Is AcceptChanges() called on the datatable before the HookPreSave method is fired?
>
>The code:
>
>
>protected override bool HookPreSave(DataTable dt) {
>   foreach (DataRow dataRow in dt.Rows)
>   {
>     if (dataRow.RowState == DataRowState.Added)
>     {
>       dataRow["Password"] = Encrypt(dataRow["Password"].ToString());
>     }
>     else if (dataRow.RowState == DataRowState.Modified)
>     {
>       // Only encrypt the password if it has been changed
>       // will return False -> dataRow.HasVersion(DataRowVersion.Proposed);
>     }
>   }
>   return base.HookPreSave(dt);
>}
>
>
>Sincerely,
>
>Einar
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform