From a012be45d4777007e4dd83ccdfe059c121579d79 Mon Sep 17 00:00:00 2001 From: Falkvinge Date: Sun, 20 Nov 2016 12:38:18 +0100 Subject: [PATCH] Checkpoint commit: security settings --- Logic/Security/Authentication.cs | 8 ++++---- Logic/Swarm/Person.cs | 4 ++-- Site/Automation/SwarmFunctions.aspx.cs | 14 ++++++++++++++ Site/Master-v5.master | 22 ++++++++++++++-------- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Logic/Security/Authentication.cs b/Logic/Security/Authentication.cs index 309e5151..8108fe3a 100644 --- a/Logic/Security/Authentication.cs +++ b/Logic/Security/Authentication.cs @@ -118,7 +118,7 @@ namespace Swarmops.Logic.Security public static string CreateWeakSecret (int length) { - string allowedChars = "ABCDEFHJKMNPQRTUVWXYZ23456789"; + string allowedChars = "abcdefhjkmnpqrtuvwxyz23456789"; char[] chars = new char[length]; Random randomizer = new Random(); @@ -417,15 +417,15 @@ namespace Swarmops.Logic.Security pers.ResetPasswordTicket = ""; } - internal static bool ValidatePassword (Person person, string oldpassword) + internal static bool ValidatePassword (Person person, string password) { - if (CheckPassword (person, oldpassword)) + if (CheckPassword (person, password)) { return true; } // If the most recent password hash mechanism fails, try legacy hashes - string[] legacyHashes = GenerateLegacyPasswordHashes (person, oldpassword); + string[] legacyHashes = GenerateLegacyPasswordHashes (person, password); foreach (string legacyHash in legacyHashes) { diff --git a/Logic/Swarm/Person.cs b/Logic/Swarm/Person.cs index c83e1c29..89ab70ac 100644 --- a/Logic/Swarm/Person.cs +++ b/Logic/Swarm/Person.cs @@ -1023,9 +1023,9 @@ namespace Swarmops.Logic.Swarm return newAddress; } - public bool ValidatePassword (string oldpassword) + public bool ValidatePassword (string password) { - return Authentication.ValidatePassword (this, oldpassword); + return Authentication.ValidatePassword (this, password); } public string HexIdentifier() diff --git a/Site/Automation/SwarmFunctions.aspx.cs b/Site/Automation/SwarmFunctions.aspx.cs index 1de65009..54e5260d 100644 --- a/Site/Automation/SwarmFunctions.aspx.cs +++ b/Site/Automation/SwarmFunctions.aspx.cs @@ -391,5 +391,19 @@ namespace Swarmops.Frontend.Automation } } + [WebMethod] + public static bool ValidatePassword(int personId, string password) + { + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + // We can only verify password for personId zero (the self) + + if (personId != 0) + { + return false; + } + + return authData.CurrentUser.ValidatePassword(password); + } } } \ No newline at end of file diff --git a/Site/Master-v5.master b/Site/Master-v5.master index 43d5849d..2a0209ea 100644 --- a/Site/Master-v5.master +++ b/Site/Master-v5.master @@ -368,17 +368,23 @@ function masterPersonEditorOnSecurityPasswordChanging(newValue, cookie, controlName) { - if (newValue == "foobar") { - if (!_master_PersonEditor_SecurityShowing) { + if (_master_PersonEditor_SecurityShowing) { + $('div.divMasterPersonEditSecurityRolldown').slideUp(); + _master_PersonEditor_SecurityShowing = false; + } + + var jsonData = + { + personId: _master_PersonEditedId, + password: newValue + } + + SwarmopsJS.ajaxCall("/Automation/SwarmFunctions.aspx/ValidatePassword", jsonData, function(result) { + if (result.d) { $('div.divMasterPersonEditSecurityRolldown').slideDown(); _master_PersonEditor_SecurityShowing = true; } - } else { - if (_master_PersonEditor_SecurityShowing) { - $('div.divMasterPersonEditSecurityRolldown').slideUp(); - _master_PersonEditor_SecurityShowing = false; - } - } + }); } function masterBeginEditPerson(personId) {