How to encrypt a password on FormView update and insert event using an EntityDataSource

I have a FormView with a textbox for a password.  The FormView is using an EntityDataSource as a data source an I am trying to apply a hash function the textbox value before it is entered into the database.

Formview:

<asp:FormView
      ID="fvUser"
      runat="server"
      DataKeyNames="id"
      DataSourceID="edsUserDetails"
      DefaultMode="ReadOnly"
      OnItemInserting="fvUser_ItemInserting"
      width="100%"
      >
        <EditItemTemplate>
              .
              .
              .
            <div class="label-Field">Password</div>
                <asp:TextBox ID="tbxPassword" runat="server" Width="200px" TextMode="Password" Text='<%# Bind("password") %>' />
         </EditItemTemplate>
</asp:FormView>

Entity Datasource:

<asp:EntityDataSource ID="edsUserDetails" runat="server"
                        ConnectionString="name=WomEntities"
                        DefaultContainerName="WomEntities"                         
                        EntitySetName="Users"
                        EnableUpdate="True"
                        EnableInsert="True"
                        OnInserted="edsUserDetails_ItemInserted"
                        OnUpdating="edsUserDetails_onUpdating"
                        AutoGenerateWhereClause="true">
                        <WhereParameters>
                              <asp:ControlParameter ControlID="fView$gvSearchResult" DbType="Int32" Name="id" PropertyName="SelectedValue" />
                        </WhereParameters>
                  </asp:EntityDataSource>

Code Behind:

protected void edsUserDetails_onUpdating( object sender, EntityDataSourceChangingEventArgs e ) {
                  TextBox ltb_password = ( TextBox )fvUser.FindControl( "tbxPassword" );
                  string lpswd = encrypt( ltb_password.Text );
                  e.Entity.password = lpswd;                  
            }

I found a blog that suggested the onUpdating method above but it is returning error:  "Error      3      'object' does not contain a definition for 'password' and no extension method 'password' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)"

Any suggestions for this.  I simply want to use the existing code and interrupt the database insert/update to hash the password.

Thank you
LVL 1
meyerc74Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NazoUKCommented:
You'll need to cast the E.Entity in the OnUpdating function to whatever your entity type is to be able to set its properties.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
meyerc74Author Commented:
thank you NazoUK....i knew it was something simple i was overlooking.  Corrected code below:

protected void edsUserDetails_onUpdating( object sender, EntityDataSourceChangingEventArgs e ) {
                  TextBox ltb_password = ( TextBox )fvUser.FindControl( "tbxPassword" );
                  string lpswd = encrypt( ltb_password.Text );
                  User lentity = (User)e.Entity;
                  lentity.password = lpswd;
            }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.