diff --git a/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.Designer.cs b/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.Designer.cs index d2b1ca16..a4941964 100644 --- a/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.Designer.cs +++ b/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.Designer.cs @@ -401,13 +401,13 @@ namespace Swarmops.Logic.App_GlobalResources { } /// - /// Looks up a localized string similar to Your [InstallationName] password was changed at [ExternalUrl]. + /// Looks up a localized string similar to Your [InstallationName] password was just changed at [ExternalUrl]. /// - ///If you did not just perform this password change, there has been a security breach. If this is the case, please block your account IMMEDIATELY by clicking the following link: + ///If you did not just perform this password change, there has been a security breach. If this is the case, please lock your account down IMMEDIATELY by clicking the following link: /// - ///[ExternalUrl]Security/LockoutAccount?Mail=[MailAddress]&Ticket=[LockoutTicket] + ///[ExternalUrl]Security/AccountLockdown?Mail=[MailAddress]&Ticket=[TicketCode] /// - ///For security purposes, there will not be a confirmation dialog: your account will be locked the instant you go to this link, and administrators will contact you to verify what happened a [rest of string was truncated]";. + ///If you confirm a lockdown on the link above, any existing sessions will terminate immediately, logons with the newly-set password will be locked out, and administrators will conta [rest of string was truncated]";. /// internal static string Password_Changed_Body { get { @@ -416,7 +416,7 @@ namespace Swarmops.Logic.App_GlobalResources { } /// - /// Looks up a localized string similar to [[InstallationName]] Password was changed. + /// Looks up a localized string similar to [[InstallationName]] Password Changed. /// internal static string Password_Changed_Subject { get { diff --git a/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.resx b/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.resx index 72307245..a32f634f 100644 --- a/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.resx +++ b/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.resx @@ -254,18 +254,18 @@ Thank you for your understanding. [[InstallationName]] Cannot Reset Password - Your [InstallationName] password was changed at [ExternalUrl]. + Your [InstallationName] password was just changed at [ExternalUrl]. -If you did not just perform this password change, there has been a security breach. If this is the case, please block your account IMMEDIATELY by clicking the following link: +If you did not just perform this password change, there has been a security breach. If this is the case, please lock your account down IMMEDIATELY by clicking the following link: -[ExternalUrl]Security/LockoutAccount?Mail=[MailAddress]&Ticket=[LockoutTicket] +[ExternalUrl]Security/AccountLockdown?Mail=[MailAddress]&Ticket=[TicketCode] -For security purposes, there will not be a confirmation dialog: your account will be locked the instant you go to this link, and administrators will contact you to verify what happened and work with you to re-enable your account. +If you confirm a lockdown on the link above, any existing sessions will terminate immediately, logons with the newly-set password will be locked out, and administrators will contact you to verify what happened and work with you to re-enable your account. -However, if it was you yourself who changed the password, and thereby caused this notification to be sent, everything is obviously fine and just as it should be. Carry on. +However, if it was you yourself who changed the password just now, and thereby caused this notification to be sent, everything is obviously fine and just as it should be. Carry on. - [[InstallationName]] Password was changed + [[InstallationName]] Password Changed People at [OrganizationName] have issued a password reset ticket to your account, presumably at your request. This ticket is valid for the next 24 hours. diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index 7ca0d6d3..20454f37 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -257,7 +257,8 @@ - + + diff --git a/Logic/Support/LogEntries/PasswordResetLogEntry.cs b/Logic/Support/LogEntries/PasswordResetLogEntry.cs new file mode 100644 index 00000000..bb6f75cc --- /dev/null +++ b/Logic/Support/LogEntries/PasswordResetLogEntry.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Swarmops.Logic.Structure; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Logic.Support.LogEntries +{ + public class PasswordResetLogEntry: SecurityActionBase + { + public PasswordResetLogEntry() + { + // empty ctor for serialization + } + + public PasswordResetLogEntry (Person concernedPerson, string remoteIPAddresses) + { + // This can only be done by the concerned person acting on ticket, so no acting person or org + this.ConcernedPersonId = concernedPerson.Identity; + this.RemoteIPAddresses = remoteIPAddresses; + } + + } +} diff --git a/Logic/Support/LogEntries/PasswordResetRequest.cs b/Logic/Support/LogEntries/PasswordResetRequestLogEntry.cs similarity index 77% rename from Logic/Support/LogEntries/PasswordResetRequest.cs rename to Logic/Support/LogEntries/PasswordResetRequestLogEntry.cs index 98efd320..d4bb8dcb 100644 --- a/Logic/Support/LogEntries/PasswordResetRequest.cs +++ b/Logic/Support/LogEntries/PasswordResetRequestLogEntry.cs @@ -10,14 +10,14 @@ using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Support.LogEntries { [Serializable] - public class PasswordResetRequest: SecurityActionBase + public class PasswordResetRequestLogEntry: SecurityActionBase { - public PasswordResetRequest() + public PasswordResetRequestLogEntry() { // empty ctor for serialization } - public PasswordResetRequest (Person concernedPerson, string remoteIPAddresses, + public PasswordResetRequestLogEntry (Person concernedPerson, string remoteIPAddresses, Person actingPerson = null, Organization organization = null) { this.ConcernedPersonId = concernedPerson.Identity; diff --git a/Logic/Swarm/Person.cs b/Logic/Swarm/Person.cs index ee0b1b7f..c132de99 100644 --- a/Logic/Swarm/Person.cs +++ b/Logic/Swarm/Person.cs @@ -4,6 +4,7 @@ using System.Drawing; using System.Globalization; using System.Text; using System.Text.RegularExpressions; +using NBitcoin; using Swarmops.Basic.Enums; using Swarmops.Basic.Interfaces; using Swarmops.Basic.Types; @@ -863,9 +864,17 @@ namespace Swarmops.Logic.Swarm } + public string AccountLockdownTicket + { + get { return OptionalData.GetOptionalDataString (ObjectOptionalDataType.AccountLockdownTicket); } + set { OptionalData.SetOptionalDataString (ObjectOptionalDataType.AccountLockdownTicket, value); } + } + + + public virtual void SetPassword (string newPassword) { - string hash = Authentication.GenerateNewPasswordHash (Identity, newPassword); + string hash = Authentication.GenerateNewPasswordHash (this, newPassword); SwarmDb.GetDatabaseForWriting().SetPersonPasswordHash (Identity, hash); base.PasswordHash = hash; } diff --git a/Site5/App_GlobalResources/Pages.Security.resx b/Site5/App_GlobalResources/Pages.Security.resx index 3903b39a..20cc6255 100644 --- a/Site5/App_GlobalResources/Pages.Security.resx +++ b/Site5/App_GlobalResources/Pages.Security.resx @@ -218,10 +218,10 @@ Re-enter your mail address - There is no valid password reset ticket for this mail address, the address does not exist, the password reset ticket is invalid, or it has expired. Password reset failed. + There is no valid password reset ticket for this mail address, the address does not exist, the password reset ticket is invalid, or it has expired.<br/><br/><strong>Password reset failed.</strong> - You're resetting the password for a user account. Enter your new password twice to set it and login. + You're resetting the password for a user account. Enter your new password twice to set it and login. (If you're trying to start the password-reset procedure, you need a ticket to do so. <a href="/Security/RequestPasswordReset">Create a ticket.</a>) Enter your mail account to send instructions to that address on how to proceed with the password reset procedure. It will contain a unique and expiring code that you will need to use to proceed. @@ -248,7 +248,7 @@ Reset - Your password was changed and you have been logged in to Swarmops using your new password. + Your password was changed and you have been logged on to Swarmops using your new password. Ticket diff --git a/Site5/Security/RequestPasswordReset.aspx.cs b/Site5/Security/RequestPasswordReset.aspx.cs index 8daf2fb9..23bdc55d 100644 --- a/Site5/Security/RequestPasswordReset.aspx.cs +++ b/Site5/Security/RequestPasswordReset.aspx.cs @@ -84,7 +84,7 @@ namespace Swarmops.Pages.Security NotificationResource.Password_ResetOnRequest); SwarmopsLog.CreateEntry (null, - new PasswordResetRequest (concernedPerson, SupportFunctions.GetRemoteIPAddressChain())); + new PasswordResetRequestLogEntry (concernedPerson, SupportFunctions.GetRemoteIPAddressChain())); return true; } diff --git a/Site5/Security/ResetPassword.aspx b/Site5/Security/ResetPassword.aspx index bad4f825..7d6591fb 100644 --- a/Site5/Security/ResetPassword.aspx +++ b/Site5/Security/ResetPassword.aspx @@ -45,14 +45,19 @@ function resetPassword() { var jsonData = {}; jsonData.mailAddress = $('#<%=this.TextMailAddress.ClientID%>').val(); - jsonData.ticket = val(); - jsonData.newPassword = val(); + jsonData.ticket = $('#<%=this.TextTicket.ClientID%>').val(); + jsonData.newPassword = $('#<%=this.TextPassword1.ClientID%>').val(); - if (jsonData.newPassword != val()) { + if (jsonData.newPassword != $('#<%=this.TextPassword2.ClientID%>').val()) { alertify.error("<%= Resources.Pages.Security.ResetPassword_NewPasswordsDontMatch %>"); return false; } + if (jsonData.newPassword == "") { + alertify.error("<%= Resources.Pages.Security.ResetPassword_NoEmpty %>"); + return false; + } + $.ajax({ type: "POST", url: "/Security/ResetPassword.aspx/PerformReset", @@ -62,8 +67,7 @@ async: false, // blocks until function returns - race conditions otherwise success: function (msg) { if (msg.d) { - $('#DivSuccessMaybe').slideDown(); - $('#DivMailEntry').slideUp(); + document.location = "/"; // success, auth cookies have been set - redirect to Dashboard } else { alertify.alert("<%= Resources.Pages.Security.ResetPassword_Failed %>"); } @@ -98,8 +102,8 @@
​
​
- ​
- ​
+ ​
+ ​
diff --git a/Site5/Security/ResetPassword.aspx.cs b/Site5/Security/ResetPassword.aspx.cs index 221eb990..f93c21bd 100644 --- a/Site5/Security/ResetPassword.aspx.cs +++ b/Site5/Security/ResetPassword.aspx.cs @@ -1,10 +1,19 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Web; +using System.Web.Configuration; +using System.Web.Security; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; +using NBitcoin.BouncyCastle.Asn1.Ocsp; +using Swarmops.Logic.Communications; +using Swarmops.Logic.Communications.Transmission; +using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; +using Swarmops.Logic.Support.LogEntries; using Swarmops.Logic.Swarm; namespace Swarmops.Pages.Security @@ -24,6 +33,7 @@ namespace Swarmops.Pages.Security { this.TextTicket.Text = suppliedTicket.Trim().ToUpperInvariant(); this.TextTicket.ReadOnly = true; + this.TextTicket.Enabled = false; } Localize(); @@ -64,12 +74,70 @@ namespace Swarmops.Pages.Security if (resetData.Length != 2) { - return false; // invalid data + return false; // invalid data or no ticket } + // This may throw on invalid data, which will give a slightly different error but that's fine too for now. + DateTime ticketExpiresUtc = DateTime.Parse(resetData[0]); + if (DateTime.UtcNow > ticketExpiresUtc) + { + // Ticket expired. + return false; + } + if (ticket != resetData[1]) + { + // Bad ticket. + return false; + } - return false; // temp + // When we get here, all checks to reset the password have completed. Change the password, log the change, + // notify the user that the password was changed, set a new authentication cookie, and have the web page + // redirect to Dashboard (by returning true). + + // Clear password reset ticket + + resetPerson.ResetPasswordTicket = string.Empty; + + // Create lockdown code, notify + + string lockdownTicket = SupportFunctions.GenerateSecureRandomKey (16); + OutboundComm.CreateSecurityNotification (resetPerson, null, null, lockdownTicket, + NotificationResource.Password_Changed); + resetPerson.AccountLockdownTicket = DateTime.UtcNow.AddDays (1).ToString (CultureInfo.InvariantCulture) + "," + + lockdownTicket; + + // Set new password + + resetPerson.SetPassword (newPassword); + + // Log the password reset + + SwarmopsLog.CreateEntry (resetPerson, + new PasswordResetLogEntry (resetPerson, SupportFunctions.GetRemoteIPAddressChain())); + + // Set authentication cookies + + int lastOrgId = resetPerson.LastLogonOrganizationId; + + if (lastOrgId == 0) + { + lastOrgId = Organization.SandboxIdentity; + } + + if (!resetPerson.MemberOfWithInherited(lastOrgId)) + { + // If the person doesn't have access to the last organization (anymore), log on to Sandbox + + lastOrgId = 1; + } + + // Set cookies + + FormsAuthentication.SetAuthCookie(resetPerson.Identity.ToString(CultureInfo.InvariantCulture) + "," + lastOrgId.ToString(CultureInfo.InvariantCulture) + ",,AuthPlain", true); + HttpContext.Current.Response.SetCookie (new HttpCookie ("DashboardMessage", Resources.Pages.Security.ResetPassword_Success)); + + return true; // temp // do NOT NOT NOT trim password - this is deliberate. Starting/ending pwds in whitespace must be possible