private bool Register() { string salt = server.registerStep1(username); string newPassword = AuthenticationPrimitives.hashPassword(password, salt); return(server.registerStep2(username, newPassword, salt)); }
public static BackupServiceClient logIn(string username, string password, out string token) { BackupServiceClient server = new BackupServiceClient(); AuthenticationData ad; token = null; try { ad = server.authStep1(username); } catch (FaultException) { throw new LoginExcpetion("Username doesn't exist!"); }catch { throw new LoginExcpetion("No internet connection!Check it and retry"); } try { token = server.authStep2(ad.token, username, AuthenticationPrimitives.hashPassword(password, ad.salt, ad.token)); } catch (FaultException) { throw new LoginExcpetion("Wrong password!"); } catch { throw new LoginExcpetion("No internet connection!Check it and retry"); } return(server); }
public void BadPasswordAuthenticationTest() { FolderBackup.Server.Server serv = new FolderBackup.Server.Server(); AuthenticationData ad = serv.authStep1("test1"); token = ad.token; Assert.IsNotNull(ad); token = serv.authStep2(ad.token, "test1", AuthenticationPrimitives.hashPassword("asd", ad.salt, ad.token)); }
public void CorrectAuthenticationTest() { FolderBackup.Server.Server serv = new FolderBackup.Server.Server(); AuthenticationData ad = serv.authStep1("test1"); token = ad.token; Assert.IsNotNull(ad); token = serv.authStep2(ad.token, "test1", AuthenticationPrimitives.hashPassword("test1", ad.salt, ad.token)); Assert.AreEqual(serv.user.rootDirectory.FullName, @"c:\folderBackup\test1"); }
private async void RegisterButton_Click(object sender, RoutedEventArgs e) { string username = this.usernameTxtBox.Text; string password = this.passwordTxtBox.Password; Config conf = Config.Instance(); if (username.Equals("")) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Missing username! Username field cannot be empty."); return; } if (password.Equals("")) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Missing password! Password field cannot be empty."); return; } BackupServiceClient server = new BackupServiceClient(); string salt; try { salt = server.registerStep1(username); } catch { UsefullMethods.setLabelAlert("danger", this.errorBox, "No internet connection! Check it and retry"); return; } if (salt == null) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Username already choosen! Try another!"); return; } if (server.registerStep2(username, AuthenticationPrimitives.hashPassword(password, salt), salt)) { conf.targetPath.set(null); conf.userName.set(username); UsefullMethods.setLabelAlert("success", this.errorBox, "Registration succeed. You can log in now."); await Task.Delay(500); this.Hide(); this.parent.Activate(); this.parent.Show(); } else { UsefullMethods.setLabelAlert("danger", this.errorBox, "Registration procedure failed!"); } }
private void TestInitialize() { server = new Server.Server(); AuthenticationData ad = server.authStep1("test1"); token = server.authStep2(ad.token, "test1", AuthenticationPrimitives.hashPassword("test1", ad.salt, ad.token)); CleanUp(); server = new Server.Server(); ad = server.authStep1("test1"); token = server.authStep2(ad.token, "test1", AuthenticationPrimitives.hashPassword("test1", ad.salt, ad.token)); string[] lines = { "First line", "Second line", "Third line" }; string[] lines1 = { "First line", "Second line", "Third lines" }; System.IO.Directory.CreateDirectory("asd"); System.IO.Directory.CreateDirectory(@"asd\ciao"); rinfo = new DirectoryInfo("asd"); System.IO.File.WriteAllLines(@"asd\uno.txt", lines); System.IO.File.WriteAllLines(@"asd\due.txt", lines1); System.IO.File.WriteAllLines(@"asd\ciao\due.txt", lines); FBVersionBuilder vb = new FBVersionBuilder(rinfo.FullName); FolderBackup.Shared.FBVersion v = (FolderBackup.Shared.FBVersion)vb.generate(); SerializedVersion serV = new SerializedVersion(v.serialize()); server.newTransaction(serV); byte[][] bfiles = server.getFilesToUpload(); FBFile file = (FBFile) new FBFileBuilder(@"asd\uno.txt").generate(); FileStream fstream = new FileStream(@"asd\uno.txt", FileMode.Open, FileAccess.Read); UploadData credential = server.uploadFile(); UsefullMethods.SendFile(credential.ip, credential.port, credential.token, fstream); fstream.Close(); file = (FBFile) new FBFileBuilder(@"asd\due.txt").generate(); fstream = new FileStream(@"asd\due.txt", FileMode.Open, FileAccess.Read); credential = server.uploadFile(); UsefullMethods.SendFile(credential.ip, credential.port, credential.token, fstream); Assert.IsTrue(server.commit()); }
public void PersistenceTest() { doTransaction(); server.commit(); server = null; server = new Server.Server(); AuthenticationData ad = server.authStep1("test1"); token = server.authStep2(ad.token, "test1", AuthenticationPrimitives.hashPassword("test1", ad.salt, ad.token)); FBVersionBuilder vb = new FBVersionBuilder(rinfo.FullName); FolderBackup.Shared.FBVersion v = (FolderBackup.Shared.FBVersion)vb.generate(); SerializedVersion serV = new SerializedVersion(v.serialize()); Assert.IsFalse(server.newTransaction(serV)); }
public void TestInitialize() { server = new Server.Server(); AuthenticationData ad = server.authStep1("test1"); token = server.authStep2(ad.token, "test1", AuthenticationPrimitives.hashPassword("test1", ad.salt, ad.token)); CleanUp(); server = new Server.Server(); ad = server.authStep1("test1"); token = server.authStep2(ad.token, "test1", AuthenticationPrimitives.hashPassword("test1", ad.salt, ad.token)); string[] lines = { "First line", "Second line", "Third line" }; string[] lines1 = { "First line", "Second line", "Third lines" }; System.IO.Directory.CreateDirectory("asd"); System.IO.Directory.CreateDirectory(@"asd\ciao"); rinfo = new DirectoryInfo("asd"); System.IO.File.WriteAllLines(@"asd\uno.txt", lines); System.IO.File.WriteAllLines(@"asd\due.txt", lines1); System.IO.File.WriteAllLines(@"asd\ciao\due.txt", lines); }