Skip to content

Commit

Permalink
修复错误,完成构建
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeDong32 authored Jul 6, 2023
2 parents 28d1779 + b9720e0 commit b5da729
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 64 deletions.
9 changes: 8 additions & 1 deletion GoodPass-CLI/Models/GPManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ public bool ChangeAccountName(string platformName, string accountName, string ne
{
return false;
}
if (AccurateSearch(platformName, newAccountName) != -1)
{
return false;
}
else
{
GPDatas[targetIndex].ChangeAccountName(newAccountName);
Expand Down Expand Up @@ -303,7 +307,10 @@ public bool LoadFormFile(string filePath)//从文件导入数据
var data = line.Split(',');
AddData(data[0], data[1], data[2], data[3], DateTime.Parse(data[4]));
}
return true;
if (GPDatas.Count != 0)
return true;
else
return false;
}
else
{
Expand Down
169 changes: 109 additions & 60 deletions GoodPass-CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class GoodPass_CLI
public static byte[]? AESKey;
public static byte[]? AESIV;
public static GPManager manager = new();
public static int cleanLinecount = 0;
public static async Task Main(string[] args)
{
#region Console Configs
Expand All @@ -24,32 +25,47 @@ public static async Task Main(string[] args)
#region Login
var checkcount = 0;
CommandLineServices.PrintStart();
if (File.Exists(Path.Combine("Data", "MKConfig.txt")))
if (File.Exists(Path.Combine(Environment.CurrentDirectory, "Data", "MKconfig.txt")))
{
do
{
Console.Write(" Please enter your master password:");
Console.Write(" Please enter your master password:"); cleanLinecount++;
var masterkey = ConsoleHelper.ReadPassword();
var mkcr = MasterKeyService.CheckMasterKeyAsync(masterkey, out AESIV, out AESKey, out EncryptBase);
switch (mkcr)
{
case "pass":
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
goto mainprocess;
case "npass":
ConsoleHelper.PrintError(" Master password incorrect, please try again.");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" Master password incorrect, please try again."); cleanLinecount++;
checkcount++;
break;
case "error: not found":
case "error: data broken":
ConsoleHelper.PrintError(" Master password config file broken, please reset...");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" Master password config file broken, please reset..."); cleanLinecount++;
var resetresult = await ResetMP();
if (resetresult)
{
for (var i = 0; i < 11; i++)
for (var i = 0; i < cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(11);
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintGreen(" Master password reset successfully, please login again.");
checkcount++;
}
Expand All @@ -61,14 +77,24 @@ public static async Task Main(string[] args)
}
break;
default:
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" Unknown Error, please check and feedback to GoodPass team");
await Task.Delay(10000);
Environment.Exit('?');
break;
}
}
while (checkcount <= 5);
Console.WriteLine(" Too many attempts, exiting...");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" Too many attempts, exiting...");
await Task.Delay(2000);
Environment.Exit(1);
}
Expand All @@ -78,9 +104,8 @@ public static async Task Main(string[] args)
var setresult = await SetMP();
if (setresult)
{
ConsoleHelper.PrintGreen(" Master password set successfully, please wait for app restart and login.");
ConsoleHelper.PrintGreen(" Master password set successfully, please restart app to login.");
await Task.Delay(1000);
System.Diagnostics.Process.Start(Path.Combine(Environment.CurrentDirectory, "GoodPass-CLI"));
Environment.Exit(0);
}
else
Expand All @@ -94,7 +119,7 @@ public static async Task Main(string[] args)
mainprocess:
Console.Clear();
CommandLineServices.PrintStart();
var loadStatus = GoodPass_CLI.manager.LoadFormFile(Path.Combine("Data", "GoodPassData.csv"));
var loadStatus = GoodPass_CLI.manager.LoadFormFile(Path.Combine(Environment.CurrentDirectory, "Data", "GoodPassData.csv"));
if (!loadStatus)
{
manager.AddData("Example", "", "test1", "ExamplePassword");
Expand All @@ -113,25 +138,31 @@ public static async Task Main(string[] args)

public static async Task<bool> SetMP()
{
ConsoleHelper.PrintWarning(" Please make sure to set your master password in a secure environment!");
Console.WriteLine(" Press \"E\" to exit. Press any other key to continue...");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintWarning(" Please make sure to set your master password in a secure environment!"); cleanLinecount++;
Console.WriteLine(" Press \"E\" to exit. Press any other key to continue..."); cleanLinecount++;
var input = Console.ReadKey(true);
if (input.Key == ConsoleKey.E)
{
return false;
}
else
{
ConsoleHelper.CleanConsoleLine(1);
ConsoleHelper.CleanConsoleLine(2);
ConsoleHelper.CleanConsoleLine(3);
ConsoleHelper.BackspaceToLine(3);
Console.WriteLine(" Please enter a master password that meets the following requirements:\n" +
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintWarning(" Please enter a master password that meets the following requirements:\n" +
" - The password length is between 10-40 characters\n" +
" - The password should be complex enough");
ConsoleHelper.PrintWarning(" - The password should not be the same as your usual password");
ConsoleHelper.PrintWarning(" You should remember your master password, as if you lose it, you can't retrieve it!");
Console.Write(" Password:");
Console.Write(" Password:"); cleanLinecount += 2;
var mk1 = ConsoleHelper.ReadPassword();
var mk1count = 1;
while (string.IsNullOrEmpty(mk1) || mk1.Length < 10 || mk1.Length > 40)
Expand All @@ -142,16 +173,17 @@ public static async Task<bool> SetMP()
await Task.Delay(2000);
Environment.Exit(1);
}
ConsoleHelper.CleanConsoleLine(1);
ConsoleHelper.CleanConsoleLine(2);
ConsoleHelper.BackspaceToLine(2);
ConsoleHelper.PrintError(" The password does not meet the requirements, please try again");
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(" Password:");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" The password does not meet the requirements, please try again"); cleanLinecount++;
Console.Write(" Password:"); cleanLinecount++;
mk1 = ConsoleHelper.ReadPassword();
mk1count++;
}
Console.Write(" Please enter your password again:");
Console.Write(" Please enter your password again:"); cleanLinecount++;
var mk2 = ConsoleHelper.ReadPassword();
var resetcount = 1;
while (mk2 != mk1)
Expand All @@ -162,12 +194,13 @@ public static async Task<bool> SetMP()
await Task.Delay(2000);
Environment.Exit(1);
}
ConsoleHelper.CleanConsoleLine(1);
ConsoleHelper.CleanConsoleLine(2);
ConsoleHelper.CleanConsoleLine(3);
ConsoleHelper.BackspaceToLine(3);
ConsoleHelper.PrintError(" Passwords do not match, please try again.");
Console.Write(" Password:");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" Passwords do not match, please try again."); cleanLinecount++;
Console.Write(" Password:"); cleanLinecount++;
mk1 = ConsoleHelper.ReadPassword();
while (string.IsNullOrEmpty(mk1) || mk1.Length < 10 || mk1.Length > 40)
{
Expand All @@ -177,15 +210,17 @@ public static async Task<bool> SetMP()
await Task.Delay(2000);
Environment.Exit(1);
}
ConsoleHelper.CleanConsoleLine(1);
ConsoleHelper.CleanConsoleLine(2);
ConsoleHelper.BackspaceToLine(2);
ConsoleHelper.PrintWarning(" The password does not meet the requirements, please try again");
Console.Write(" Password:");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" The password does not meet the requirements, please try again"); cleanLinecount++;
Console.Write(" Password:"); cleanLinecount++;
mk1 = ConsoleHelper.ReadPassword();
mk1count++;
}
Console.Write(" Please enter your password again:");
Console.Write(" Please enter your password again:"); cleanLinecount++;
mk2 = ConsoleHelper.ReadPassword();
resetcount++;
}
Expand All @@ -196,21 +231,31 @@ public static async Task<bool> SetMP()

public static async Task<bool> ResetMP()
{
ConsoleHelper.PrintWarning(" Please make sure to reset your master password in a secure environment!");
Console.WriteLine(" Press \"E\" to exit. Press any other key to continue...");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintWarning(" Please make sure to reset your master password in a secure environment!"); cleanLinecount++;
Console.WriteLine(" Press \"E\" to exit. Press any other key to continue..."); cleanLinecount++;
var input = Console.ReadKey(true);
if (input.Key == ConsoleKey.E)
{
return false;
}
else
{
Console.WriteLine(" Please enter a master password that meets the following requirements:\n" +
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintWarning(" Please enter a master password that meets the following requirements:\n" +
" - The password length is between 10-40 characters\n" +
" - The password should be complex enough");
ConsoleHelper.PrintWarning(" - The password should not be the same as your usual password");
ConsoleHelper.PrintWarning(" You should remember your master password, as if you lose it, you can't retrieve it!");
Console.Write(" Password:");
Console.Write(" Password:"); cleanLinecount += 2;
var mk1 = ConsoleHelper.ReadPassword();
var mk1count = 1;
while (string.IsNullOrEmpty(mk1) || mk1.Length < 10 || mk1.Length > 40)
Expand All @@ -221,16 +266,17 @@ public static async Task<bool> ResetMP()
await Task.Delay(2000);
Environment.Exit(1);
}
ConsoleHelper.CleanConsoleLine(1);
ConsoleHelper.CleanConsoleLine(2);
ConsoleHelper.BackspaceToLine(2);
ConsoleHelper.PrintError(" The password does not meet the requirements, please try again");
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(" Password:");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" The password does not meet the requirements, please try again"); cleanLinecount++;
Console.Write(" Password:"); cleanLinecount++;
mk1 = ConsoleHelper.ReadPassword();
mk1count++;
}
Console.Write(" Please enter your password again:");
Console.Write(" Please enter your password again:"); cleanLinecount++;
var mk2 = ConsoleHelper.ReadPassword();
var resetcount = 1;
while (mk2 != mk1)
Expand All @@ -241,12 +287,13 @@ public static async Task<bool> ResetMP()
await Task.Delay(2000);
Environment.Exit(1);
}
ConsoleHelper.CleanConsoleLine(1);
ConsoleHelper.CleanConsoleLine(2);
ConsoleHelper.CleanConsoleLine(3);
ConsoleHelper.BackspaceToLine(3);
ConsoleHelper.PrintError(" Passwords do not match, please try again.");
Console.Write(" Password:");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" Passwords do not match, please try again."); cleanLinecount++;
Console.Write(" Password:"); cleanLinecount++;
mk1 = ConsoleHelper.ReadPassword();
while (string.IsNullOrEmpty(mk1) || mk1.Length < 10 || mk1.Length > 40)
{
Expand All @@ -256,15 +303,17 @@ public static async Task<bool> ResetMP()
await Task.Delay(2000);
Environment.Exit(1);
}
ConsoleHelper.CleanConsoleLine(1);
ConsoleHelper.CleanConsoleLine(2);
ConsoleHelper.BackspaceToLine(2);
ConsoleHelper.PrintError(" The password does not meet the requirements, please try again");
Console.Write(" Password:");
for (var i = 1; i <= cleanLinecount; i++)
{
ConsoleHelper.CleanConsoleLine(i);
}
ConsoleHelper.BackspaceToLine(cleanLinecount); cleanLinecount = 0;
ConsoleHelper.PrintError(" The password does not meet the requirements, please try again"); cleanLinecount++;
Console.Write(" Password:"); cleanLinecount++;
mk1 = ConsoleHelper.ReadPassword();
mk1count++;
}
Console.Write(" Please enter your password again:");
Console.Write(" Please enter your password again:"); cleanLinecount++;
mk2 = ConsoleHelper.ReadPassword();
resetcount++;
}
Expand Down
3 changes: 3 additions & 0 deletions GoodPass-CLI/Services/CommandLineServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public static void PrintHelp()
public static void PrintStart()
{
Console.WriteLine($"GoodPass CLI {GoodPass_CLI._version} [.NET {Environment.Version}] on {Environment.OSVersion}");
#region Dev test info
//Console.WriteLine($"Running on path: {Environment.CurrentDirectory}");
#endregion
Console.WriteLine("Type \"help\" or \"about\" to get more information. Type \"exit\" to leave safely.");
}

Expand Down
2 changes: 1 addition & 1 deletion GoodPass-CLI/Services/GoodPassAESServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static byte[] GetLocalIV(string masterKey)
if (localIVStr == String.Empty || localIVStr == null)
{
localIV = GenerateIV(masterKey);
SetLocalIV(localIV);
//SetLocalIV(localIV);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions GoodPass-CLI/Services/MasterKeyServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class MasterKeyService
/// <param name="MasterKey">主密码</param>
public static bool SetLocalMKHash(string MasterKey)
{
var dataPath = Path.Combine("Data");
var dataPath = Path.Combine(Environment.CurrentDirectory, "Data");
var MKconfigPath = Path.Combine(dataPath, "MKconfig.txt");
if (!System.IO.Directory.Exists(dataPath))
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public static bool SetLocalMKHash(string MasterKey)
/// <returns>本地哈希校验值</returns>
public static async Task<string> GetLocalMKHashAsync()/*ToDo:通过RATAsync的异常机制精简方法*/
{
var MKconfigPath = Path.Combine("Data", "MKconfig.txt");
var MKconfigPath = Path.Combine(Environment.CurrentDirectory, "Data", "MKconfig.txt");
var localMKHash = string.Empty;
try
{
Expand Down

0 comments on commit b5da729

Please sign in to comment.