Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: Encrypt a password in FoxPro?

$
0
0
Re: Encrypt a password in FoxPro?
West Wind Client Tools
Re: Encrypt a password in FoxPro?
04/26/2012
02:39:16 PM
3HL0VDYI9 Show this entire thread in new window
Gratar Image based on email address
From:
Matt Slay
To:
Attachments:
None
I agree with you about using the MD5Hash in the manner you are describing.

However, in this case, I am configuring an email routine where I need to decrypt the email account password from the app configuration table, so I can set a property on the wwStmp class which is required to athenticate with my SMTP server. So, I *MUST* be able to retrieve the password for this purpse, but I don't want anyone on the network to open that table and see the password sitting there.



Like Phil I tend to do one way passwords which are written encoded to the database and can't be reversed. For password lookups you can then encrypt what you're searching for and find that in the database.

The nice thing about this is that you can use MD5 for encoding (plus I suggest some salting with pre and post strings), which doesn't require much in the way of resources or extra tooling. Web Connection has the HashMd5 function that does the encoding.

Here's some logic I use in most of my .NET apps to do this - it's easily ported to Fox code:

public static string EncodePassword(string password) { // don't allow empty password if (string.IsNullOrEmpty(password)) return string.Empty; string salt = "2112"; string salted = salt + password + salt; MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] Hash = md5.ComputeHash(Encoding.ASCII.GetBytes(password)); return Convert.ToBase64String(Hash).Replace("==", "") + // add a marker so we know whether a password is encoded App.PasswordEncodingPostfix; }


The last line in Fox code can be done with this using wwApi.prg:

lcPassword = STRTRAN( STRCONV(HashMd5("asdasd"),13),"==","")


+++ Rick ---


Rick - I'm wanting to encrypt a password before I save it to a DBF table, and un-encrypt when I read it back out of the table. I'm creating a basic app login strategy (client app, not web).

Do any of your Client Tools classes provided this feature? Or can you recommend anything?

I'd prefer a pure FoxPro solution if possible, but I could use wwDotNetBride if I have to.



Viewing all articles
Browse latest Browse all 10393

Trending Articles