diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-08-13 18:03:16 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-08-13 18:03:16 +0300 |
| commit | e7819d9ffabb1efc272e61b4ef93a67d33dca57a (patch) | |
| tree | 8a5e4250f5ccf11f395855130c3b9bc534fe3506 /Software/Visual_Studio/Utilities/Tango.PasswordChanger.CLI/Program.cs | |
| parent | d687f750aee6db3819893f5ac7dab144774aecdd (diff) | |
| download | Tango-e7819d9ffabb1efc272e61b4ef93a67d33dca57a.tar.gz Tango-e7819d9ffabb1efc272e61b4ef93a67d33dca57a.zip | |
Implemented password changed util.
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.PasswordChanger.CLI/Program.cs')
| -rw-r--r-- | Software/Visual_Studio/Utilities/Tango.PasswordChanger.CLI/Program.cs | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.PasswordChanger.CLI/Program.cs b/Software/Visual_Studio/Utilities/Tango.PasswordChanger.CLI/Program.cs new file mode 100644 index 000000000..c7ded88a7 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.PasswordChanger.CLI/Program.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.Core; +using Tango.Web; + +namespace Tango.PasswordChanger.CLI +{ + class Program + { + private static DataSource dataSource = new DataSource(); + + static void Main(string[] args) + { + dataSource.Address = "twine.database.windows.net"; + dataSource.IntegratedSecurity = false; + dataSource.UserName = "Roy"; + dataSource.Password = "Aa123456"; + + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("Welcome to password changed!"); + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine(); + Console.Write("Select Environments (eg DEV,TEST): "); + String envString = Console.ReadLine(); + + Console.Write("Email: "); + String email = Console.ReadLine(); + Console.Write("Password: "); + String password = Console.ReadLine(); + + try + { + if (envString.IsNotNullOrEmpty()) + { + String[] envs = envString.Split(',').Select(x => x.Trim()).ToArray(); + + foreach (var env in envs) + { + ChangePassword($"Tango_{env.ToUpper()}", email, password); + } + } + else + { + foreach (var env in Enum.GetValues(typeof(DeploymentSlot)).Cast<DeploymentSlot>()) + { + ChangePassword($"Tango_{env.ToString()}", email, password); + } + } + + Console.WriteLine(); + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Done!"); + } + catch (Exception ex) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(); + Console.WriteLine(ex.ToString()); + } + + Console.ForegroundColor = ConsoleColor.Yellow; + Console.Write("Continue? :"); + var key = Console.ReadKey(); + + if (key.Key == ConsoleKey.Y) + { + Console.WriteLine(); + Main(null); + } + } + + private static void ChangePassword(String catalog, String email, String password) + { + if (catalog == "Tango_PROD") + { + catalog = "Tango"; + } + + Console.WriteLine($"Changing password on '{catalog}' for '{email}' to '{password}'..."); + + dataSource.Catalog = catalog; + + using (ObservablesContext db = ObservablesContext.CreateDefault(dataSource)) + { + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == email.ToLower()); + + if (user == null) + { + throw new KeyNotFoundException($"User {email} not found."); + } + + Core.Cryptography.IHashGenerator gen = new Core.Cryptography.BasicHashGenerator(); + user.Password = gen.Encrypt(password); + + db.SaveChanges(); + } + } + } +} |
