3

I have a single string that contain a password in my program. I want save it as something like P-code that Matlab can read it but user cant open or see it.I get this string password from user (edit box). I don't want save all active or open variables, only I want save this single string to a protected file.

What function should I use?

Thanks.

1 Answer 1

1

Usually when you deal with passwords people store their hash values, not the passwords in a plain text. Then when you check if password is correct, you just compare the hash values of password written by the user against that in the database/file you store. In matlab you can get MD5 or SH1 hash of a string using its embedded java.

for example:

 md = java.security.MessageDigest.getInstance('MD5');
 md5 = md.digest(uint8('my_secret_password'))'
 % gives: 126  -28   22  -43   39  -94  -48   71  117   28    2  109 -126  -37  -66  -17

 md = java.security.MessageDigest.getInstance('SHA1');
 md5 = md.digest(uint8('my_secret_password'))'
 % gives: 51  -91  -61   39    0   56  -19  -61  112  -10    9  -71 -111  117  117  -71   52   46   50 -122
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your answer. Nobody can't return this "hash values" to "String" ? Another question. Suppose that user can change the password. Where should I save this new password. I think I must have a secure file like p-code for storing this new password. Is this true?
@user2991243 There is no way of changing hash to string, except brute force. Thus, when user forgets password, you just generate new one, as you cant recover it. When a user provides new password, you change the stored hash value to new one. For storing hashed password, you can use a database. It depends how many users you have, etc.
Thank you for answer. As you said for storing passwords of my users it is better to connect my program to something like MySQL. Is this true? There inst any way to store password in a secured mat file?
@user2991243 I don't think matlab has some build in way to encrypt files. There are many threads about this giving some possible ways of doing that. One is here for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.