Page 1 of 1

Encrypt / Decrypt Passwords in the Database

PostPosted: Mon Jul 09, 2018 11:10 am
by SBarnes
Hi Mike,

Is there a stored procedure in the database that will either encrypt or decrypt a HR_Staff password?

To explain the problem we are working on upgrading the web site of a customer who uses an old version of Jiwa that allows staff members to login using their Jiwa credentials and all the stored procedures of course assume that the password field in HR_Staff is clear text.

I can add a custom field to HR_Staff to get around it but would prefer not to for several obvious reasons i.e. two passwords would be confusing and storing the password as plain text isn't what I want to do.

Given this is using and extending the web API, if there is a simple way to encrypt the plain string and then call the ORMLite stored proc function with that it would work as an alternative I just need to know how to do it?

Re: Encrypt / Decrypt Passwords in the Database  Topic is solved

PostPosted: Mon Jul 09, 2018 2:16 pm
by SBarnes
Ok so after some hunting around this is how to do it

Code: Select all
            JiwaFinancials.Jiwa.JiwaServiceModel.Tables.HR_Staff hrstaff = Db.Select<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.HR_Staff>().Where(s=> s.SName == request.LogonCode ).FirstOrDefault();
            if (hrstaff == null)
            {
               return result;
            }
            JiwaFinancials.Jiwa.JiwaEncryption.JiwaEncrypt jiwaEncrypt = new JiwaFinancials.Jiwa.JiwaEncryption.JiwaEncrypt();
            DateTime PDate = hrstaff.PasswordLastChangedDateTime == null ? DateTime.Now : (DateTime) hrstaff.PasswordLastChangedDateTime;
            string pwdenc = jiwaEncrypt.EncryptString(request.LogonPassword, manager.Database.FormatDateTime(PDate, true));