sql - How to sha1 hash a c# login application -
i want make password hash password sha1 tried make passlogin = sha1(@passlogin)
not working
here code
using (sqlcommand cmd = new sqlcommand("select * loginreport userlogin = @userlogin , passlogin = @passlogin", conn)) { conn.open(); cmd.parameters.addwithvalue("@userlogin", txtuser.text); cmd.parameters.addwithvalue("@passlogin", txtpass.text); sqldatareader dr = cmd.executereader(); if (dr.hasrows == true) { messagebox.show("successfully login"); form1 formreports = new form1(); formreports.showdialog(); application.exit(); } else { messagebox.show("check username , password again!!"); } }
it seems you're not hashing value before assigning parameter.
you may first want try hashing input string, see included code (not tested!) example how this:
public static string generatesaltedsha1(string plaintextstring) { hashalgorithm algorithm = new sha1managed(); var saltbytes = generatesalt(4); var plaintextbytes = encoding.ascii.getbytes(plaintextstring); var plaintextwithsaltbytes = appendbytearray(plaintextbytes, saltbytes); var saltedsha1bytes = algorithm.computehash(plaintextwithsaltbytes); var saltedsha1withappendedsaltbytes = appendbytearrays(saltedsha1bytes, saltbytes); return "{ssha}" + convert.tobase64string(saltedsha1withappendedsaltbytes); } private static byte[] generatesalt(int saltsize) { var rng = new rngcryptoserviceprovider(); var buff = new byte[saltsize]; rng.getbytes(buff); return buff; } private static byte[] appendbytearray(byte[] bytearray1, byte[] bytearray2) { var bytearrayresult = new byte[bytearray1.length + bytearray2.length]; (var = 0; < bytearray1.length; i++) bytearrayresult[i] = bytearray1[i]; (var = 0; < bytearray2.length; i++) bytearrayresult[bytearray1.length + i] = bytearray2[i]; return bytearrayresult; }
i advise use stronger hashing algorithm sha1 since it's become easy current technology create huge rainbow tables find original string of hash. please salt hash!
Comments
Post a Comment