Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
 public void Read (TProtocol iprot)
 {
   TField field;
   iprot.ReadStructBegin();
   while (true)
   {
     field = iprot.ReadFieldBegin();
     if (field.Type == TType.Stop) { 
       break;
     }
     switch (field.ID)
     {
       case 0:
         if (field.Type == TType.Struct) {
           Success = new DNHAuthResponse();
           Success.Read(iprot);
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       default: 
         TProtocolUtil.Skip(iprot, field.Type);
         break;
     }
     iprot.ReadFieldEnd();
   }
   iprot.ReadStructEnd();
 }