Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Diagnostics;
- using System.Net;
- using Renci.SshNet;
- using System.Threading;
- using System.Xml;
- namespace USB_auth
- {
- class Program
- {
- static void Main(string[] args)
- {
- string Host = "ts.norwhales.com";
- int Port = 20522;
- String RemoteFileName = "/home/henrik/passwd/passwd.kdbx";
- string dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"passwd\\");
- if (!Directory.Exists(dir))
- {
- Directory.CreateDirectory(dir);
- }
- var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "passwd\\passwd.kdbx");
- Console.WriteLine(fileName);
- String LocalDestinationFilename = fileName;
- String Username = "henrik";
- string pass = "";
- bool tryagain = true;
- while (tryagain)
- {
- try
- {
- Console.Write("Passord: ");
- ConsoleKeyInfo key;
- pass = "";
- do
- {
- key = Console.ReadKey(true);
- if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
- {
- pass += key.KeyChar;
- Console.Write("*");
- }
- else
- {
- if (key.Key == ConsoleKey.Backspace && pass.Length > 0)
- {
- pass = pass.Substring(0, (pass.Length - 1));
- Console.Write("\b \b");
- }
- }
- }
- while (key.Key != ConsoleKey.Enter);
- Console.WriteLine();
- tryagain = false;
- using (var sftp = new SftpClient(Host, Port, Username, pass))
- {
- sftp.Connect();
- using (var file = File.OpenWrite(LocalDestinationFilename))
- {
- sftp.DownloadFile(RemoteFileName, file);
- }
- sftp.Disconnect();
- }
- }
- catch (Renci.SshNet.Common.SshAuthenticationException)
- {
- Console.WriteLine("Feil passord!");
- tryagain = true;
- }
- }
- Console.WriteLine("Ferdig!");
- Console.WriteLine("Åpner Keepass");
- try
- {
- string xmlFile = "KeePass.config.xml";
- System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
- xmlDoc.PreserveWhitespace = true;
- xmlDoc.Load(xmlFile);
- xmlDoc.SelectSingleNode("Configuration/Application/LastUsedFile/Path").InnerText = fileName;
- xmlDoc.Save(xmlFile);
- Process.Start("KeePass.exe");
- }
- catch (System.ComponentModel.Win32Exception)
- {
- Console.WriteLine("Kunne ikke åpne Keepass! Vær sikker på at Keepass er installert i samme mappe som dette programmet!");
- }
- catch (FileNotFoundException)
- {
- Console.WriteLine("Keepass konfigurasjonsfil ikke funnet! Kontroller at KeePass er installert i samme mappe som dette programmet");
- }
- Thread.Sleep(3000);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement