One time password on forgot password

This commit is contained in:
Alexander Trofimov 2015-05-17 23:47:38 +03:00
parent 5f6e13c645
commit 1e0a0710fd
16 changed files with 326 additions and 109 deletions

View file

@ -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);
}
}
}