cyclonebri Posted October 14, 2003 Posted October 14, 2003 Hey Everybody, Hopefully this is an easy one but I can't seem to find the answer through search, so I apologize in advance if this has already been posted. A simple problem. I have a string that I want to iterate by character, converting each character to it's ascii representation. I was wondering how I can accomplish this without making a table with the values and just finding them...my goal is to mask a plain text password stored in an XML file for later retrieval (since we don't use the registry anymore). Basically the user logs in and I want the ability to remember their settings like a cookie would do on a web page, but this is a desktop app. I have all the code I need, except the ability to convert an unknown character (variable tmpChar) to it's ascii representation. I do this: for (int i = 0; i<mPassword.Length; i++) { tmpStr = mPassword.Substring(i,1); tmpChar = Convert.ToChar(tmpStr); //convert to ascii //tmpInt = SomeConvertFunction(tmpChar); //if I have to I could write a function but I'd rather not do that } Thanks in advance for any help! Brian Quote
Administrators PlausiblyDamp Posted October 14, 2003 Administrators Posted October 14, 2003 No offence but that would be a pretty easy to crack scheme. A much better way is to not store the password in any way shape or form but store a hash of the password. When the user enters their password - hash it and compare to the stored hash. Best place to look is under System.Security.Cryptography at their implementation of SHA or similar. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
cyclonebri Posted October 14, 2003 Author Posted October 14, 2003 no offense taken, I understand how easy this would be to crack :) I didn't say that was the only method of security, just happens to be a portion of it ;), in any event it will still be easy to crack :). I'm just looking for fast solutions. I will look under the System.Security.Cryptography and see what it has to offer. Thanks for the heads up :) Brian Quote
cyclonebri Posted October 14, 2003 Author Posted October 14, 2003 Well, just in case anyone ever cares about doing something like this in the future, I have found a site online that has helped and have used the code to produce a solution. The code can be found HERE and when implemented could look something like this: byte[] Bytstr = new byte[mPassword.Length]; System.Text.Encoding.ASCII.GetBytes(mPassword.ToCharArray(),0,mPassword.Length,Bytstr,0); byte myByte; string[] tmpBytStr = new string[mPassword.Length]; for(int i = 0; i<mPassword.Length;i++) { myByte = Bytstr[i]; tmpBytStr[i] = myByte.ToString(); } hope this will help someone out in the future :) Take care, Brian Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.