upd Authentification
This commit is contained in:
43
SvetoforVKBot/Services/EmailService.cs
Normal file
43
SvetoforVKBot/Services/EmailService.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using MimeKit;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MailKit.Net.Smtp;
|
||||
using System.Configuration;
|
||||
using SvetoforVKBot.App_Start;
|
||||
|
||||
namespace SvetoforVKBot.Services
|
||||
{
|
||||
public class EmailService
|
||||
{
|
||||
public async Task SendEmailAsync(string email, string subject, string message)
|
||||
{
|
||||
var emailMessage = new MimeMessage();
|
||||
|
||||
emailMessage.From.Add(new MailboxAddress(
|
||||
((WebConfiguration)ConfigurationManager.GetSection("smtpClient")).FromName,
|
||||
((WebConfiguration)ConfigurationManager.GetSection("smtpClient")).Email));
|
||||
emailMessage.To.Add(new MailboxAddress("", email));
|
||||
emailMessage.Subject = subject;
|
||||
emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
|
||||
{
|
||||
Text = message
|
||||
};
|
||||
|
||||
using (var client = new SmtpClient())
|
||||
{
|
||||
//await client.ConnectAsync("mail.hosting.reg.ru", 465);
|
||||
await client.ConnectAsync(
|
||||
((WebConfiguration)ConfigurationManager.GetSection("smtpClient")).Host,
|
||||
((WebConfiguration)ConfigurationManager.GetSection("smtpClient")).Port,
|
||||
(MailKit.Security.SecureSocketOptions)((WebConfiguration)ConfigurationManager.GetSection("smtpClient")).SSO);
|
||||
await client.AuthenticateAsync(
|
||||
((WebConfiguration)ConfigurationManager.GetSection("smtpClient")).UserName,
|
||||
((WebConfiguration)ConfigurationManager.GetSection("smtpClient")).Password);
|
||||
await client.SendAsync(emailMessage);
|
||||
await client.DisconnectAsync(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
46
SvetoforVKBot/Services/PasswordService.cs
Normal file
46
SvetoforVKBot/Services/PasswordService.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SvetoforVKBot.Services
|
||||
{
|
||||
public class PasswordService
|
||||
{
|
||||
public static string GeneratePassword()
|
||||
{
|
||||
|
||||
int length = 6;
|
||||
|
||||
StringBuilder password = new StringBuilder();
|
||||
Random random = new Random();
|
||||
|
||||
while (password.Length < length)
|
||||
{
|
||||
int c = random.Next(0, 9);
|
||||
password.Append(c);
|
||||
}
|
||||
|
||||
return password.ToString();
|
||||
}
|
||||
|
||||
public static string CreateMD5(string input)
|
||||
{
|
||||
// Use input string to calculate MD5 hash
|
||||
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
|
||||
{
|
||||
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
|
||||
byte[] hashBytes = md5.ComputeHash(inputBytes);
|
||||
|
||||
// Convert the byte array to hexadecimal string
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < hashBytes.Length; i++)
|
||||
{
|
||||
sb.Append(hashBytes[i].ToString("X2"));
|
||||
}
|
||||
return sb.ToString().ToLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user