This repository was archived by the owner on Dec 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmAuth.cs
More file actions
53 lines (46 loc) · 1.65 KB
/
frmAuth.cs
File metadata and controls
53 lines (46 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DiscordBot.Common;
using Google.Authenticator;
using MelissaNet;
namespace DiscordBot
{
public partial class frmAuth : Form
{
public frmAuth()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.txtAccountTitle.Text = "MogiiBot3";
string key = Guid.NewGuid().ToString().Replace("-", "");
this.txtSecretKey.Text = key;
Configuration.UpdateConfiguration(secretKey: Cryptography.EncryptString(key));
TwoFactorAuthenticator tfA = new TwoFactorAuthenticator();
var setupCode = tfA.GenerateSetupCode(this.txtAccountTitle.Text, this.txtSecretKey.Text, pbQR.Width, pbQR.Height);
WebClient wc = new WebClient();
MemoryStream ms = new MemoryStream(wc.DownloadData(setupCode.QrCodeSetupImageUrl));
this.pbQR.Image = Image.FromStream(ms);
}
private void btnTest_Click(object sender, EventArgs e)
{
TwoFactorAuthenticator tfA = new TwoFactorAuthenticator();
var result = tfA.ValidateTwoFactorPIN(txtSecretKey.Text, this.txtCode.Text);
MessageBox.Show(result ? "Code Valid! TwoAuth setup successful." : "Incorrect", "Result");
if (result)
{
Close();
}
}
}
}