Click or drag to resize

SealSecurityDefaultResetPasswordScript2 Field

Default implementation used when ResetPasswordScript2 is empty: checks the token and changes the password of the login

Namespace: Seal.Model
Assembly: SealLibrary (in SealLibrary.dll) Version: 10.0.1.0+a44cd3a7f03c2bf3cdbd971a878c679e40bed08a
Syntax
C#
public const string DefaultResetPasswordScript2 = "@using Newtonsoft.Json\n@{\n    SecurityUser user = Model;\n    var repository = user.Security.Repository;\n    var security = user.Security;\n    var guid = user.WebUserName;\n\n    //Implementation using Logins defined in the security\n    if (!Helper.IsPasswordComplex(user.WebPassword)) throw new Exception(repository.TranslateWeb("Your password must contain at least 8 characters, including at least one uppercase letter, one number, and one special character (e.g., !@#$%^&*)."));\n\n    var vals = CryptoHelper.DecryptWithRSAContainer(user.Token, "Reset" + guid, false).Split("\r");\n    if (vals.Length != 3 || vals[1] != guid) throw new Exception("Invalid token");\n    var generationDate = JsonConvert.DeserializeObject<DateTime>(vals[2]);\n    //Check date\n    if (DateTime.Now > generationDate.AddMinutes(10)) throw new Exception("The token is not valid anymore.");\n\n    var id = vals[0];\n    user.WebUserName = id;\n    var login = security.Logins.FirstOrDefault(i => i.Id == id);\n    if (login == null && id.Contains("@")) login = security.Logins.FirstOrDefault(i => i.Email == id);\n\n    if (login == null) throw new Exception("Invalid login in token.");\n\n    login.HashedPassword = user.WebPassword;\n    security.SaveToFile();\n\n    if (!string.IsNullOrEmpty(login.Email))\n    {\n        var message = repository.TranslateWeb("Your password has been changed after a Reset.");\n        var from = ""; //Default of the device will be used\n        var to = login.Email;\n        var subject = repository.TranslateWeb("Seal Report Password Change");\n        var body = $"{message}<br>";\n        if (!repository.SendNotificationEmail(from, to, subject, true, body)) Audit.LogEventAudit(AuditType.EventError, "Unable to send email for Change Password afer Reset.");\n    }\n}\n"

Field Value

String
See Also