Username ABC
Password DEF
Salt = Username + Password IE; ABCDEF(saltkey)
Now, this salt key is hashed using SHA256 algorithm and the output for the saltkey(ABCDEF) after hashing it is: jjaiBx04mbD1ZvsLKuG6PyBFfJcYbl7iCnDCsi2l4tk=
Now how do I truncate this to a smaller hash so that the result is just the first 10 characters of it let say: jjaiBx04mb
You can use
String.Substring:This will return the substring of the original string that starts at position
startand has lengthlength.Therefore, giving start a value of
0will yield the firstlengthcharacters of the original string.However, if I may make a suggestion, assuming that it is within your control, do not create salts this way. Use a completely random sequence of characters, preferably created using a secure random generator, and store it alongside the username and hashed password. Also, do make your salt fairly long. I'm sure you can spare the extra few bytes of DB space it will require.