Password encryption and binding

  • Thread starter Thread starter Earl
  • Start date Start date
E

Earl

I'm adding password encryption to the Employees form. I have a
strongly-typed dataset being used as the datasource for the
EmployeesBindingSource, and the Employees table set as the datamember. All
controls on the form are bound to the EmployeesBindingSource. Except for the
password ...

I set up separate handlers for the Password and bind this control manually
when I New() the form:

Private Sub BindPasswordControl()
Dim b As Binding = New Binding("Text", EmployeesBindingSource,
"Password")
AddHandler b.Format, AddressOf PasswordFormat
AddHandler b.Parse, AddressOf PasswordParse
txtPassword.DataBindings.Add(b)
End Sub

Private Sub PasswordFormat(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If IsDBNull(e.Value) = False Then
e.Value = EncryptPassword(CStr(e.Value))
End If
End Sub

The handlers ARE being called, however, the Password column of the
strongly-typed dataset does not get changed to the password entered into the
Password textbox (it remains null). I can also see that the e.Value is being
passed to the EncryptPassword function. Yet when I check the datatable, the
Password column is empty (all other columns have the correct data). What the
heck am I overlooking here!?
 
Hi,

Earl said:
I'm adding password encryption to the Employees form. I have a
strongly-typed dataset being used as the datasource for the
EmployeesBindingSource, and the Employees table set as the datamember. All
controls on the form are bound to the EmployeesBindingSource. Except for
the password ...

I set up separate handlers for the Password and bind this control manually
when I New() the form:

Private Sub BindPasswordControl()
Dim b As Binding = New Binding("Text", EmployeesBindingSource,
"Password")
AddHandler b.Format, AddressOf PasswordFormat
AddHandler b.Parse, AddressOf PasswordParse
txtPassword.DataBindings.Add(b)
End Sub

Private Sub PasswordFormat(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If IsDBNull(e.Value) = False Then
e.Value = EncryptPassword(CStr(e.Value))
End If
End Sub

Where is the PasswordParse sub ?
The handlers ARE being called, however, the Password column of the
strongly-typed dataset does not get changed to the password entered into
the Password textbox (it remains null). I can also see that the e.Value is
being passed to the EncryptPassword function. Yet when I check the
datatable, the Password column is empty (all other columns have the
correct data). What the heck am I overlooking here!?

According to your code, EncryptPassword is called inside PasswordFormat,
Format means DataSource->Control. If you ask me you should call
EncryptPassword inside Parse and DecryptPassword inside Format....

HTH,
Greetings
 
You are correct, the Encrypt/Decrypt were backwards. Two sets of eyes are
better than one. Thanks.
 
Back
Top