3

I've hashed the password and then I'll insert it to the database but the problem here is that each time I try to do this query this occurs

Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary'

in my table in the database accnt_pass is Binary(50), here's my code

//Instantiate a new Hasher Object
var hasher = new Hasher();

hasher.SaltSize = 16;

//Encrypts The password
var encryptedPassword = hasher.Encrypt(txtPass.Text);

Account newUser = new Account();

newUser.accnt_User = txtUser.Text;
newUser.accnt_Position = txtPosition.Text;
newUser.accnt_Pass = encryptedPassword; 

and I am using Encrypto for hashing,

1 Answer 1

7

You need to convert the string encryptedPassword to a byte array if your sql column is of binary type. So instead of the line

newUser.accnt_Pass = encryptedPassword;

put

System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
newUser.accnt_Pass = new System.Data.Linq.Binary(encoding.GetBytes(encryptedPassword));
Sign up to request clarification or add additional context in comments.

3 Comments

R after that? can I directly insert it on my table?
Okay thank you, by the way, How come when I inserted the same password on different accounts(for testing puposes) they both have differentt values? how will I know if the one typed is the same as the one in the database?
I think you should ask this as a separate question and tag it with Encrypto so that people who are familiar with this utility can help. But I can make an educated guess that generating different hashes for the same password is point of salted hashes.

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.