using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Security.Cryptography;
public int Login(string UserName, string password)
{
int result = 0;
try {
//Encrypt Password
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] hashedDataBytes = null;
UTF8Encoding encoder = new UTF8Encoding();
hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(password));
//If password = "3hotminds" Then
// bAdminLogin = True
// Return GetUserId(UserName)
//End If
result = Authenticate(UserName, password);
bAdminLogin = false;
if (result == 1) {
return GetUserId(UserName);
}
} catch (Exception Exception) {
return -1;
}
return result;
}
public int Authenticate(string sUserName, string sPassword)
{
int result = -1;
FileOnDatabase db = new FileOnDatabase();
SqlParameter[] @params = new SqlParameter[3];
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] hashedDataBytes = null;
UTF8Encoding encoder = new UTF8Encoding();
hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(sPassword));
try {
db.ConnectionString = sConnectionString;
@params(0) = db.MakeParameter("@Username", sUserName);
@params(1) = db.MakeParameter("@Password", SqlDbType.Binary, 16);
@params(1).Value = hashedDataBytes;
@params(2) = db.MakeParameter("@Result", ParameterDirection.Output, result);
db.RunProcedure("Authenticate", @params);
result = @params(2).Value;
} catch (Exception e) {
_errorMessage = "Unable to Add the permissions [" + e.Message + "]";
result = -1;
} finally {
db = null;
}
return result;
}
Here in database uid in varchar type and password is in binary type .