Completed: Password Reset

This commit is contained in:
Rick Falkvinge
2015-01-29 16:16:59 +01:00
parent 909cf17e5d
commit 8f516a3cc3
10 changed files with 137 additions and 29 deletions
@@ -401,13 +401,13 @@ namespace Swarmops.Logic.App_GlobalResources {
}
/// <summary>
/// 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]&amp;Ticket=[LockoutTicket]
///[ExternalUrl]Security/AccountLockdown?Mail=[MailAddress]&amp;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]&quot;;.
///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]&quot;;.
/// </summary>
internal static string Password_Changed_Body {
get {
@@ -416,7 +416,7 @@ namespace Swarmops.Logic.App_GlobalResources {
}
/// <summary>
/// Looks up a localized string similar to [[InstallationName]] Password was changed.
/// Looks up a localized string similar to [[InstallationName]] Password Changed.
/// </summary>
internal static string Password_Changed_Subject {
get {
@@ -254,18 +254,18 @@ Thank you for your understanding.</value>
<value>[[InstallationName]] Cannot Reset Password</value>
</data>
<data name="Password_Changed_Body" xml:space="preserve">
<value>Your [InstallationName] password was changed at [ExternalUrl].
<value>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]&amp;Ticket=[LockoutTicket]
[ExternalUrl]Security/AccountLockdown?Mail=[MailAddress]&amp;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.</value>
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.</value>
</data>
<data name="Password_Changed_Subject" xml:space="preserve">
<value>[[InstallationName]] Password was changed</value>
<value>[[InstallationName]] Password Changed</value>
</data>
<data name="Password_ResetByCrew_Body" xml:space="preserve">
<value>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.
+2 -1
View File
@@ -257,7 +257,8 @@
<Compile Include="Support\IXmlPayload.cs" />
<Compile Include="Support\LogEntries\CashAdvanceRequestedLogEntry.cs" />
<Compile Include="Support\LogEntries\MembershipActionBase.cs" />
<Compile Include="Support\LogEntries\PasswordResetRequest.cs" />
<Compile Include="Support\LogEntries\PasswordResetLogEntry.cs" />
<Compile Include="Support\LogEntries\PasswordResetRequestLogEntry.cs" />
<Compile Include="Support\LogEntries\PersonAddedLogEntry.cs" />
<Compile Include="Support\LogEntries\SalaryCreatedLogEntry.cs" />
<Compile Include="Support\LogEntries\InboundInvoiceCreatedLogEntry.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;
}
}
}
@@ -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;
+10 -1
View File
@@ -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;
}
@@ -218,10 +218,10 @@
<value>Re-enter your mail address</value>
</data>
<data name="ResetPassword_Failed" xml:space="preserve">
<value>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.</value>
<value>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.&lt;br/&gt;&lt;br/&gt;&lt;strong&gt;Password reset failed.&lt;/strong&gt;</value>
</data>
<data name="ResetPassword_Info" xml:space="preserve">
<value>You're resetting the password for a user account. Enter your new password twice to set it and login.</value>
<value>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. &lt;a href="/Security/RequestPasswordReset"&gt;Create a ticket.&lt;/a&gt;)</value>
</data>
<data name="ResetPassword_InfoRequest" xml:space="preserve">
<value>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.</value>
@@ -248,7 +248,7 @@
<value>Reset</value>
</data>
<data name="ResetPassword_Success" xml:space="preserve">
<value>Your password was changed and you have been logged in to Swarmops using your new password.</value>
<value>Your password was changed and you have been logged on to Swarmops using your new password.</value>
</data>
<data name="ResetPassword_Ticket" xml:space="preserve">
<value>Ticket</value>
+1 -1
View File
@@ -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;
}
+11 -7
View File
@@ -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 @@
<div class="entryFields">
<asp:TextBox runat="server" ID="TextMailAddress" />&#8203;<br/>
<asp:TextBox runat="server" ID="TextTicket" />&#8203;<br/>
<asp:TextBox runat="server" ID="TextPassword1" />&#8203;<br/>
<asp:TextBox runat="server" ID="TextPassword2" />&#8203;<br/>
<asp:TextBox runat="server" ID="TextPassword1" TextMode="Password" />&#8203;<br/>
<asp:TextBox runat="server" ID="TextPassword2" TextMode="Password" />&#8203;<br/>
<asp:Button ID="ButtonRequest" runat="server" CssClass="buttonAccentColor NoInputFocus" OnClientClick="return resetPassword();" Text="XYZ Request"/>
</div>
<div class="entryLabels">
+70 -2
View File
@@ -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