I've been writing apps for years now, but I've just recently been tasked with writing a very simple Lightswitch app to act as an internal tool for our dev team to edit the dev database on the web app we are currently building.
Part of the app needs to edit the user table, and be able to add/edit users in the database, and thus needs to be able to at least write an encrypted hash in the DB.
Problem is I'm using an external blowfish implementation to provide the hashes and salts for the passwords, and not any of the built in stuff.
So my question is this, how in any of the inputs I have on the screens I design, can I accept a plain string, then have my custom encryption saved in the database, I thought a computed property might have been what I needed but it's not.
I'm using lightswitch under visual studio 2013 enterprise in the C# language with .NET 4.5 as the base line and SqlServer as the back end data store.
Cheers Shawty
After a weekend of playing (You just never get chance to do things like this in the office :-) ) I came up with the following solution that seems to work.
In my case the encryption library I was using is "CryptSharp" Crypt Sharp Home Page, but because I'm creating a desktop client using silverlight, cryptsharp wouldn't install due to it needing a full .NET runtime.
This lead me to start investigating what I had access to at the data tier of the application:
After reading a few blog posts and some more MSDN, I figured out that I could hook an updating function.
More specifically, if you add custom code to the data tier, you get an "Updating" (and others) for each of your data object models, and thus (After adding CryptSharp via NuGet), I ended up with:
partial void Users_Updating(User entity)
{
string encryptedPassword = "";
string encryptedSalt = "";
GenerateEncryptedPasswordAndSalt(entity.Password, out encryptedPassword, out encryptedSalt);
entity.Password = encryptedPassword;
entity.PasswordSalt = encryptedSalt;
}
Which sweetly and simply applies my encryption to what ever was typed into the form prior to save being clicked, then refreshes the form to show the encrypted password and salt.
What I may do, is make the actual password read-only, and have a pop up to enter the plain text password, so there's no confusion, but for now this solves my problem.
@Chris Cook - thanks for your suggestion, it's given me a little more to explore (I really don't do much with LightSwitch to be honest) and new exploration of things is always interesting. If you have any comments on how I solved this, I'd still be interested in hearing the pro's and cons.