meyerc74
asked on
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="edsUserDetai ls"
DefaultMode="ReadOnly"
OnItemInserting="fvUser_It emInsertin g"
width="100%"
>
<EditItemTemplate>
.
.
.
<div class="label-Field">Passwo rd</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=Wom Entities"
DefaultContainerName="WomE ntities"
EntitySetName="Users"
EnableUpdate="True"
EnableInsert="True"
OnInserted="edsUserDetails _ItemInser ted"
OnUpdating="edsUserDetails _onUpdatin g"
AutoGenerateWhereClause="t rue">
<WhereParameters>
<asp:ControlParameter ControlID="fView$gvSearchR esult" DbType="Int32" Name="id" PropertyName="SelectedValu e" />
</WhereParameters>
</asp:EntityDataSource>
Code Behind:
protected void edsUserDetails_onUpdating( object sender, EntityDataSourceChangingEv entArgs 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
Formview:
<asp:FormView
ID="fvUser"
runat="server"
DataKeyNames="id"
DataSourceID="edsUserDetai
DefaultMode="ReadOnly"
OnItemInserting="fvUser_It
width="100%"
>
<EditItemTemplate>
.
.
.
<div class="label-Field">Passwo
<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=Wom
DefaultContainerName="WomE
EntitySetName="Users"
EnableUpdate="True"
EnableInsert="True"
OnInserted="edsUserDetails
OnUpdating="edsUserDetails
AutoGenerateWhereClause="t
<WhereParameters>
<asp:ControlParameter ControlID="fView$gvSearchR
</WhereParameters>
</asp:EntityDataSource>
Code Behind:
protected void edsUserDetails_onUpdating(
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
protected void edsUserDetails_onUpdating(
TextBox ltb_password = ( TextBox )fvUser.FindControl( "tbxPassword" );
string lpswd = encrypt( ltb_password.Text );
User lentity = (User)e.Entity;
lentity.password = lpswd;
}