datenbank hinzugefügt
This commit is contained in:
parent
efe0ca9dd3
commit
1ef978a3d0
38
MailServer/DataBase/MysqlConnector.cs
Normal file
38
MailServer/DataBase/MysqlConnector.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;*/
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
|
namespace MailServer.DataBase
|
||||||
|
{
|
||||||
|
class MysqlConnector
|
||||||
|
{
|
||||||
|
private string server = "localhost";
|
||||||
|
private string db = "";
|
||||||
|
private string user = "root";
|
||||||
|
private string pass = "mafia";
|
||||||
|
private MySqlConnection connection;
|
||||||
|
public MysqlConnector()
|
||||||
|
{
|
||||||
|
string myConnectionString = "SERVER=" + server + ";" +
|
||||||
|
"DATABASE=" + db + ";" +
|
||||||
|
"UID=" + user + ";" +
|
||||||
|
"PASSWORD=" + pass + ";";
|
||||||
|
connection = new MySqlConnection(myConnectionString);
|
||||||
|
}
|
||||||
|
~MysqlConnector()
|
||||||
|
{
|
||||||
|
connection.Close();
|
||||||
|
}
|
||||||
|
public MySqlDataReader read(string sql)
|
||||||
|
{
|
||||||
|
MySqlCommand command = connection.CreateCommand();
|
||||||
|
command.CommandText = sql;
|
||||||
|
connection.Open();
|
||||||
|
MySqlDataReader reader = command.ExecuteReader();
|
||||||
|
connection.Close();
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
MailServer/DataBase/MysqlImap.cs
Normal file
42
MailServer/DataBase/MysqlImap.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
/*using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;*/
|
||||||
|
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
|
namespace MailServer.DataBase
|
||||||
|
{
|
||||||
|
class MysqlImap
|
||||||
|
{
|
||||||
|
private MysqlConnector mysql;
|
||||||
|
public MysqlImap()
|
||||||
|
{
|
||||||
|
mysql = new MysqlConnector();
|
||||||
|
}
|
||||||
|
public bool checkUser(string user, string pass)
|
||||||
|
{
|
||||||
|
MySqlDataReader reader = mysql.read("SELECT `pass` FROM `users` WHERE `user` = '"+escape(user)+"';");
|
||||||
|
if(!reader.HasRows)
|
||||||
|
return false;
|
||||||
|
while(reader.Read()) {
|
||||||
|
if(reader.GetString(0) == pass)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string escape(string str)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Regex.Replace(str,@"(\\)([\000\010\011\012\015\032\042\047\134\140])","$2");
|
||||||
|
}
|
||||||
|
catch(Exception)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,10 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="MySql.Data, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>E:\Programme\MySql\CS\Assemblies\MySql.Data.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
@ -44,6 +48,8 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="DataBase\MysqlConnector.cs" />
|
||||||
|
<Compile Include="DataBase\MysqlImap.cs" />
|
||||||
<Compile Include="LumiSoft\IMAP\IMAP_ACL_Flags.cs">
|
<Compile Include="LumiSoft\IMAP\IMAP_ACL_Flags.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -105,10 +111,18 @@
|
|||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.Delegates.cs" />
|
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.Delegates.cs" />
|
||||||
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.Events.cs" />
|
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.Events.cs">
|
||||||
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.EventsDeclarations.cs" />
|
<SubType>Component</SubType>
|
||||||
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.Properties.cs" />
|
</Compile>
|
||||||
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.Session.cs" />
|
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.EventsDeclarations.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.Properties.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="LumiSoft\IMAP\Server\IMAP_Server\IMAP_Server.Session.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="LumiSoft\IMAP\Server\IMAP_Session\IMAP_Session.cs">
|
<Compile Include="LumiSoft\IMAP\Server\IMAP_Session\IMAP_Session.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -13,7 +13,9 @@ namespace MailServer.Services
|
|||||||
{
|
{
|
||||||
void server_AuthUser(object sender, AuthUser_EventArgs e)
|
void server_AuthUser(object sender, AuthUser_EventArgs e)
|
||||||
{
|
{
|
||||||
|
e.Validated = database.checkUser(e.UserName, e.PasswData);
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void server_CopyMessage(object sender, Message_EventArgs e)
|
void server_CopyMessage(object sender, Message_EventArgs e)
|
||||||
|
@ -8,17 +8,20 @@ using System.ServiceProcess;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using LumiSoft.IMAP.Server;
|
using LumiSoft.IMAP.Server;
|
||||||
|
using MailServer.DataBase;
|
||||||
|
|
||||||
namespace MailServer.Services
|
namespace MailServer.Services
|
||||||
{
|
{
|
||||||
public partial class IMAP_Service : ServiceBase
|
public partial class IMAP_Service : ServiceBase
|
||||||
{
|
{
|
||||||
private IMAP_Server server;
|
private IMAP_Server server;
|
||||||
|
private MysqlImap database;
|
||||||
|
|
||||||
public IMAP_Service()
|
public IMAP_Service()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
putEvents();
|
database = new MysqlImap();
|
||||||
|
putEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putEvents()
|
private void putEvents()
|
||||||
|
Loading…
Reference in New Issue
Block a user