mirror of
https://github.com/tenrok/Rfid-Credential-Provider.git
synced 2026-06-20 20:10:33 +03:00
Z-2 USB Reader
This commit is contained in:
+58
-63
@@ -7,80 +7,75 @@ using System.Threading;
|
||||
|
||||
namespace TestWizard
|
||||
{
|
||||
public delegate void RfidRead(string id);
|
||||
public class RFID
|
||||
{
|
||||
private SerialPort p;
|
||||
public delegate void RfidRead(string id);
|
||||
public class RFID
|
||||
{
|
||||
private SerialPort p;
|
||||
|
||||
private const int baud = 9600;
|
||||
private const Parity parity = Parity.None;
|
||||
private const int dataBits = 8;
|
||||
private const StopBits stopBits = StopBits.One;
|
||||
private const int baud = 9600;
|
||||
private const Parity parity = Parity.None;
|
||||
private const int dataBits = 8;
|
||||
private const StopBits stopBits = StopBits.One;
|
||||
|
||||
public event RfidRead IncomingRfid;
|
||||
public event RfidRead IncomingRfid;
|
||||
|
||||
private Thread readThread;
|
||||
private bool continueReading = false;
|
||||
private Thread readThread;
|
||||
private bool continueReading = false;
|
||||
|
||||
private string Port = "COM3";
|
||||
private string Port = "COM3";
|
||||
|
||||
public RFID()
|
||||
{
|
||||
init();
|
||||
}
|
||||
public RFID()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
public RFID(int port)
|
||||
{
|
||||
Port = "COM" + port;
|
||||
public RFID(int port)
|
||||
{
|
||||
Port = "COM" + port;
|
||||
init();
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
public RFID(string port)
|
||||
{
|
||||
Port = port;
|
||||
init();
|
||||
}
|
||||
|
||||
public RFID(string port)
|
||||
{
|
||||
Port = port;
|
||||
private void init()
|
||||
{
|
||||
p = new SerialPort(Port, baud, parity, dataBits, stopBits);
|
||||
if (!continueReading)
|
||||
{
|
||||
continueReading = true;
|
||||
readThread = new Thread(Read);
|
||||
readThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
public void Close()
|
||||
{
|
||||
continueReading = false;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
p = new SerialPort(Port, baud, parity, dataBits, stopBits);
|
||||
private void Read()
|
||||
{
|
||||
p.Open();
|
||||
|
||||
if (!continueReading)
|
||||
{
|
||||
continueReading = true;
|
||||
readThread = new Thread(Read);
|
||||
readThread.Start();
|
||||
}
|
||||
while (continueReading)
|
||||
{
|
||||
string result = p.ReadLine();
|
||||
|
||||
// Strip out meta-text
|
||||
//result = result.Replace("\u0003", "");
|
||||
//result = result.Replace("\u0002", "");
|
||||
result = result.Replace("\r", "");
|
||||
result = result.Replace("\n", "");
|
||||
//result = string.Concat(result.Select(x => ((int)x).ToString("x")));
|
||||
|
||||
}
|
||||
IncomingRfid(result);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
continueReading = false;
|
||||
}
|
||||
|
||||
private void Read()
|
||||
{
|
||||
|
||||
p.Open();
|
||||
|
||||
while (continueReading)
|
||||
{
|
||||
string result = p.ReadLine();
|
||||
|
||||
// Strip out meta-text
|
||||
result = result.Replace("\u0003", "");
|
||||
result = result.Replace("\u0002", "");
|
||||
result = result.Replace("\r", "");
|
||||
result = result.Replace("\n", "");
|
||||
|
||||
IncomingRfid(result);
|
||||
}
|
||||
|
||||
p.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
p.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,118 +5,115 @@ using Microsoft.Win32;
|
||||
|
||||
namespace TestWizard
|
||||
{
|
||||
class RegistryAccess
|
||||
{
|
||||
private static bool isBoxed = (IntPtr.Size == 4 && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")));
|
||||
public static readonly RegistryKey Primary = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, (isBoxed) ? RegistryView.Registry64 : RegistryView.Default).OpenSubKey("SOFTWARE\\Tyler Menezes\\Rfid Login", true);
|
||||
private static readonly RegistryKey Keys = Primary.OpenSubKey("Keys", true);
|
||||
class RegistryAccess
|
||||
{
|
||||
private static bool isBoxed = (IntPtr.Size == 4 && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")));
|
||||
public static readonly RegistryKey Primary = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, (isBoxed) ? RegistryView.Registry64 : RegistryView.Default).OpenSubKey("SOFTWARE\\KORNET\\WinLogin", true);
|
||||
private static readonly RegistryKey Keys = Primary.OpenSubKey("Keys", true);
|
||||
|
||||
private string RfidToken;
|
||||
private string RfidToken;
|
||||
|
||||
public RegistryAccess(string token)
|
||||
{
|
||||
RfidToken = token;
|
||||
}
|
||||
public RegistryAccess(string token)
|
||||
{
|
||||
RfidToken = token;
|
||||
}
|
||||
|
||||
public string Username
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDecryptedValue(System.Text.Encoding.ASCII.GetString((byte[])TokenKey.GetValue("Username")));
|
||||
}
|
||||
set
|
||||
{
|
||||
TokenKey.SetValue("Username", System.Text.Encoding.ASCII.GetBytes(GetEncryptedValue(value)), RegistryValueKind.Binary);
|
||||
}
|
||||
}
|
||||
|
||||
public string Username
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDecryptedValue(System.Text.Encoding.ASCII.GetString((byte[])TokenKey.GetValue("Username")));
|
||||
}
|
||||
set
|
||||
{
|
||||
TokenKey.SetValue("Username", System.Text.Encoding.ASCII.GetBytes(GetEncryptedValue(value)), RegistryValueKind.Binary);
|
||||
}
|
||||
}
|
||||
public string Password
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDecryptedValue(System.Text.Encoding.ASCII.GetString((byte[])TokenKey.GetValue("Password")));
|
||||
}
|
||||
set
|
||||
{
|
||||
TokenKey.SetValue("Password", System.Text.Encoding.ASCII.GetBytes(GetEncryptedValue(value)), RegistryValueKind.Binary);
|
||||
}
|
||||
}
|
||||
|
||||
public string Password
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDecryptedValue(System.Text.Encoding.ASCII.GetString((byte[])TokenKey.GetValue("Password")));
|
||||
}
|
||||
set
|
||||
{
|
||||
TokenKey.SetValue("Password", System.Text.Encoding.ASCII.GetBytes(GetEncryptedValue(value)), RegistryValueKind.Binary);
|
||||
}
|
||||
}
|
||||
public string Domain
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDecryptedValue(System.Text.Encoding.ASCII.GetString((byte[])TokenKey.GetValue("Domain")));
|
||||
}
|
||||
set
|
||||
{
|
||||
TokenKey.SetValue("Domain", System.Text.Encoding.ASCII.GetBytes(GetEncryptedValue(value)), RegistryValueKind.Binary);
|
||||
}
|
||||
}
|
||||
|
||||
public string Domain
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDecryptedValue(System.Text.Encoding.ASCII.GetString((byte[])TokenKey.GetValue("Domain")));
|
||||
}
|
||||
set
|
||||
{
|
||||
TokenKey.SetValue("Domain", System.Text.Encoding.ASCII.GetBytes(GetEncryptedValue(value)), RegistryValueKind.Binary);
|
||||
}
|
||||
}
|
||||
private string GetEncryptedValue(string toEncrypt)
|
||||
{
|
||||
char[] e = toEncrypt.ToCharArray();
|
||||
string key = Hash(RfidToken + TokenSalt);
|
||||
for (int i = 0; i < toEncrypt.Length; i++)
|
||||
{
|
||||
e[i] = (char)(e[i] ^ key[i % key.Length]);
|
||||
e[i] = (char)(((int)e[i]) + 1);
|
||||
}
|
||||
return new string(e);
|
||||
}
|
||||
|
||||
private string GetEncryptedValue(string toEncrypt)
|
||||
{
|
||||
char[] e = toEncrypt.ToCharArray();
|
||||
string key = Hash(RfidToken + TokenSalt);
|
||||
for (int i = 0; i < toEncrypt.Length; i++)
|
||||
{
|
||||
e[i] = (char)(e[i] ^ key[i % key.Length]);
|
||||
e[i] = (char)(((int)e[i]) + 1);
|
||||
}
|
||||
private string GetDecryptedValue(string toDecrypt)
|
||||
{
|
||||
char[] e = toDecrypt.ToCharArray();
|
||||
string key = Hash(RfidToken + TokenSalt);
|
||||
for (int i = 0; i < toDecrypt.Length; i++)
|
||||
{
|
||||
e[i] = (char)(((int)e[i]) - 1);
|
||||
e[i] = (char)(e[i] ^ key[i % key.Length]);
|
||||
}
|
||||
return new string(e);
|
||||
}
|
||||
|
||||
return new string(e);
|
||||
}
|
||||
private string TokenSalt
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)TokenKey.GetValue("Salt");
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDecryptedValue(string toDecrypt)
|
||||
{
|
||||
char[] e = toDecrypt.ToCharArray();
|
||||
string key = Hash(RfidToken + TokenSalt);
|
||||
for (int i = 0; i < toDecrypt.Length; i++)
|
||||
{
|
||||
e[i] = (char)(((int)e[i]) - 1);
|
||||
e[i] = (char)(e[i] ^ key[i % key.Length]);
|
||||
}
|
||||
private RegistryKey TokenKey
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Keys.OpenSubKey(Hash(RfidToken + KeySalt)) == null)
|
||||
{
|
||||
Keys.CreateSubKey(Hash(RfidToken + KeySalt));
|
||||
Keys.OpenSubKey(Hash(RfidToken + KeySalt), true).SetValue("Salt", Hash(((new Random()).Next(Int32.MaxValue) + DateTime.Now.Ticks).ToString()));
|
||||
}
|
||||
return Keys.OpenSubKey(Hash(RfidToken + KeySalt), true);
|
||||
}
|
||||
}
|
||||
|
||||
return new string(e);
|
||||
}
|
||||
private static string KeySalt
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)Keys.GetValue("Salt");
|
||||
}
|
||||
}
|
||||
|
||||
private string TokenSalt
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)TokenKey.GetValue("Salt");
|
||||
}
|
||||
}
|
||||
|
||||
private RegistryKey TokenKey
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Keys.OpenSubKey(Hash(RfidToken + KeySalt)) == null)
|
||||
{
|
||||
Keys.CreateSubKey(Hash(RfidToken + KeySalt));
|
||||
Keys.OpenSubKey(Hash(RfidToken + KeySalt), true).SetValue("Salt", Hash(((new Random()).Next(Int32.MaxValue) + DateTime.Now.Ticks).ToString()));
|
||||
}
|
||||
return Keys.OpenSubKey(Hash(RfidToken + KeySalt), true);
|
||||
}
|
||||
}
|
||||
|
||||
private static string KeySalt
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)Keys.GetValue("Salt");
|
||||
}
|
||||
}
|
||||
|
||||
private static string Hash(string toHash)
|
||||
{
|
||||
System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
|
||||
byte[] data = System.Text.Encoding.ASCII.GetBytes(toHash);
|
||||
data = x.ComputeHash(data);
|
||||
string o = BitConverter.ToString(data).Replace("-", "").ToUpper();
|
||||
return o;
|
||||
}
|
||||
}
|
||||
private static string Hash(string toHash)
|
||||
{
|
||||
System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
|
||||
byte[] data = System.Text.Encoding.ASCII.GetBytes(toHash);
|
||||
data = x.ComputeHash(data);
|
||||
string o = BitConverter.ToString(data).Replace("-", "").ToUpper();
|
||||
return o;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,48 +42,6 @@
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile />
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DocumentationFile />
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn />
|
||||
<Optimize>false</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile />
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DocumentationFile />
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn />
|
||||
<Optimize>true</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>none</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
|
||||
@@ -41,48 +41,6 @@
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile />
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DocumentationFile />
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn />
|
||||
<Optimize>false</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile />
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DocumentationFile />
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn />
|
||||
<Optimize>true</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>none</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
|
||||
@@ -41,48 +41,6 @@
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile />
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DocumentationFile />
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn />
|
||||
<Optimize>false</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile />
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DocumentationFile />
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn />
|
||||
<Optimize>true</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>none</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
|
||||
Reference in New Issue
Block a user