-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathfrmPassword.cs
113 lines (88 loc) · 3.71 KB
/
frmPassword.cs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
Technitium Bit Chat
Copyright (C) 2015 Shreyas Zare ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using BitChatCore;
using System;
using System.IO;
using System.Windows.Forms;
namespace BitChatApp
{
public partial class frmPassword : Form
{
#region variables
string _profileFilePath;
bool _isPortableApp;
string _profileFolder;
BitChatProfile _profile;
#endregion
#region constructor
public frmPassword(string profileFilePath, bool isPortableApp, string profileFolder)
{
InitializeComponent();
_profileFilePath = profileFilePath;
_isPortableApp = isPortableApp;
_profileFolder = profileFolder;
labProfileName.Text = Path.GetFileNameWithoutExtension(_profileFilePath);
}
#endregion
#region private
private void btnOK_Click(object sender, EventArgs e)
{
try
{
using (FileStream fS = new FileStream(_profileFilePath, FileMode.Open, FileAccess.Read))
{
_profile = new BitChatProfile(fS, txtPassword.Text, _isPortableApp, _profileFolder);
}
DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
catch
{
try
{
using (FileStream fS = new FileStream(_profileFilePath + ".bak", FileMode.Open, FileAccess.Read))
{
_profile = new BitChatProfile(fS, txtPassword.Text, _isPortableApp, _profileFolder);
}
DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
catch
{
MessageBox.Show("Invalid password or file data tampered. Please try again.", "Invalid Password!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtPassword.Text = "";
txtPassword.Focus();
}
}
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Close();
}
private void lnkForgotPassword_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (MessageBox.Show("Since the profile password is used to encrypt the profile data, there is no method to recover the encryption password or the profile data.\r\n\r\nTo access Bit Chat, you will need to register a new profile and you can use the same email address for registration. You will lose all your settings and you will have to join all your chats again.\r\n\r\nDo you want to register a new profile now?", "Register New Profile?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
this.DialogResult = System.Windows.Forms.DialogResult.Yes;
this.Close();
}
}
#endregion
#region properties
public BitChatProfile Profile
{ get { return _profile; } }
#endregion
}
}