One time password on forgot password
This commit is contained in:
parent
5f6e13c645
commit
1e0a0710fd
16 changed files with 326 additions and 109 deletions
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class OneTimePasswordHelper
|
||||
{
|
||||
public static string SetOneTimePassword(int userId)
|
||||
{
|
||||
int passwordLength = 12; // default length
|
||||
|
||||
// load password policy
|
||||
UserSettings userSettings = UserController.GetUserSettings(userId, UserSettings.WEBSITEPANEL_POLICY);
|
||||
string passwordPolicy = userSettings["PasswordPolicy"];
|
||||
|
||||
if (!String.IsNullOrEmpty(passwordPolicy))
|
||||
{
|
||||
// get third parameter - max length
|
||||
try
|
||||
{
|
||||
passwordLength = Utils.ParseInt(passwordPolicy.Split(';')[2].Trim(), passwordLength);
|
||||
}
|
||||
catch { /* skip */ }
|
||||
}
|
||||
|
||||
// generate password
|
||||
var password = Utils.GetRandomString(passwordLength);
|
||||
|
||||
DataProvider.SetUserOneTimePassword(userId, CryptoUtils.Encrypt(password), (int) OneTimePasswordStates.Active);
|
||||
|
||||
return password;
|
||||
}
|
||||
|
||||
public static void FireSuccessAuth(UserInfoInternal user)
|
||||
{
|
||||
DataProvider.SetUserOneTimePassword(user.UserId, CryptoUtils.Encrypt(user.Password), (int) OneTimePasswordStates.Expired);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue