Created
May 27, 2013 02:27
-
-
Save PJensen/5654883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Authenticate | |
/// </summary> | |
/// <param name="userName">the user name</param> | |
/// <param name="passwordHash">the password hash</param> | |
/// <returns>an auth response object containing -1 on auth failure</returns> | |
DNHAuthResponse DNHService.Iface.Authenticate(string userName, string passwordHash) | |
{ | |
LogCallback(string.Format("Authenticating {0}", userName)); | |
DNHAuthResponse retVal = new DNHAuthResponse() | |
{ | |
ID = -1, | |
Message = "", | |
}; | |
try | |
{ | |
using (var dbConn = new SqlConnection(Properties.Settings.Default.DSN)) | |
{ | |
dbConn.Open(); | |
const string sqlText = "SELECT [ID] FROM [User] WHERE [Name] = @Name AND [PasswordHash] = @PasswordHash"; | |
using (SqlCommand cmd = new SqlCommand(sqlText, dbConn)) | |
{ | |
cmd.Parameters.AddWithValue("@Name", userName); | |
cmd.Parameters.AddWithValue("@PasswordHash", passwordHash); | |
using (var dr = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow)) | |
{ | |
if (!dr.Read()) | |
{ | |
retVal.Message = "Invalid username / password"; | |
} | |
else | |
{ | |
retVal.ID = (int)dr[0]; | |
} | |
} | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
retVal.Message = ex.Message; | |
} | |
return retVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment