Skip to content

Commit 7c9e250

Browse files
zyhfishtpluscode
authored andcommitted
DNN-23673: encrypt the verification code with membersip user key.
1 parent 99bf222 commit 7c9e250

File tree

4 files changed

+62
-7
lines changed

4 files changed

+62
-7
lines changed

DNN Platform/Library/Entities/Users/UserController.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,13 +2244,14 @@ public static void VerifyUser(string verificationCode)
22442244

22452245
int portalId;
22462246
int userId;
2247+
var userIdString = strings[1];
22472248

2248-
if (!int.TryParse(strings[0], out portalId) || !int.TryParse(strings[1], out userId))
2249+
if (!int.TryParse(strings[0], out portalId) || string.IsNullOrWhiteSpace(userIdString))
22492250
{
22502251
throw new InvalidVerificationCodeException();
22512252
}
22522253

2253-
var user = GetUserById(int.Parse(strings[0]), int.Parse(strings[1]));
2254+
var user = int.TryParse(userIdString, out userId) ? GetUserById(portalId, userId) : GetUserByMembershipUserKey(portalId, userIdString);
22542255

22552256
if (user == null)
22562257
{
@@ -2315,7 +2316,15 @@ private static string GetDomainName(PortalAliasInfo portalAlias)
23152316
return httpAlias.IndexOf("/", StringComparison.InvariantCulture) != -1 ?
23162317
httpAlias.Substring(0, httpAlias.IndexOf("/", StringComparison.InvariantCulture)) :
23172318
httpAlias;
2318-
}
2319+
}
2320+
2321+
private static UserInfo GetUserByMembershipUserKey(int portalId, string membershipUserKey)
2322+
{
2323+
var masterPortalId = GetEffectivePortalId(portalId);
2324+
var user = MembershipProvider.Instance().GetUserByProviderUserKey(masterPortalId, membershipUserKey);
2325+
FixMemberPortalId(user, portalId);
2326+
return user;
2327+
}
23192328

23202329
#endregion
23212330

DNN Platform/Library/Entities/Users/UserInfo.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
using DotNetNuke.Entities.Profile;
3232
using DotNetNuke.Entities.Users.Social;
3333
using DotNetNuke.Security;
34+
using DotNetNuke.Security.Membership;
3435
using DotNetNuke.Security.Roles;
3536
using DotNetNuke.Services.Tokens;
3637
using DotNetNuke.UI.WebControls;
@@ -304,7 +305,7 @@ public string GetProperty(string propertyName, string format, CultureInfo format
304305
return PropertyAccess.ContentLocked;
305306
}
306307
var ps = PortalSecurity.Instance;
307-
var code = ps.Encrypt(Config.GetDecryptionkey(), PortalID + "-" + UserID);
308+
var code = ps.Encrypt(Config.GetDecryptionkey(), PortalID + "-" + GetMembershipUserId());
308309
return code.Replace("+", ".").Replace("/", "-").Replace("=", "_");
309310
case "affiliateid":
310311
if (internScope < Scope.SystemMessages)
@@ -422,6 +423,11 @@ private bool isAdminUser(ref UserInfo accessingUser)
422423
return accessingUser.IsInRole(_administratorRoleName) || accessingUser.IsSuperUser;
423424
}
424425

426+
private string GetMembershipUserId()
427+
{
428+
return MembershipProvider.Instance().GetProviderUserKey(this)?.Replace("-", string.Empty) ?? string.Empty;
429+
}
430+
425431
#endregion
426432

427433
#region Public Methods

DNN Platform/Library/Security/Membership/AspNetMembershipProvider.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,17 @@ private static MembershipUser GetMembershipUser(string userName)
605605
userName), GetMembershipUserCallBack);
606606
}
607607

608-
private static string GetCacheKey(string userName)
608+
private static MembershipUser GetMembershipUserByUserKey(string userKey)
609609
{
610-
return String.Format("MembershipUser_{0}", userName);
610+
return
611+
CBO.GetCachedObject<MembershipUser>(
612+
new CacheItemArgs(GetCacheKey(userKey), DataCache.UserCacheTimeOut, DataCache.UserCachePriority,
613+
userKey), GetMembershipUserByUserKeyCallBack);
614+
}
615+
616+
private static string GetCacheKey(string cacheKey)
617+
{
618+
return $"MembershipUser_{cacheKey}";
611619
}
612620

613621
private static object GetMembershipUserCallBack(CacheItemArgs cacheItemArgs)
@@ -617,7 +625,13 @@ private static object GetMembershipUserCallBack(CacheItemArgs cacheItemArgs)
617625
return System.Web.Security.Membership.GetUser(userName);
618626
}
619627

620-
628+
private static object GetMembershipUserByUserKeyCallBack(CacheItemArgs cacheItemArgs)
629+
{
630+
string userKey = cacheItemArgs.ParamList[0].ToString();
631+
632+
return System.Web.Security.Membership.GetUser(new Guid(userKey));
633+
}
634+
621635
private UserInfo GetUserByAuthToken(int portalId, string userToken, string authType)
622636
{
623637
IDataReader dr = _dataProvider.GetUserByAuthToken(portalId, userToken, authType);
@@ -1226,6 +1240,22 @@ public override UserInfo GetUserByPasswordResetToken(int portalId, string resetT
12261240
return user;
12271241
}
12281242

1243+
public override string GetProviderUserKey(UserInfo user)
1244+
{
1245+
return GetMembershipUser(user).ProviderUserKey?.ToString().Replace("-", string.Empty) ?? string.Empty;
1246+
}
1247+
1248+
public override UserInfo GetUserByProviderUserKey(int portalId, string providerUserKey)
1249+
{
1250+
var userName = GetMembershipUserByUserKey(providerUserKey)?.UserName ?? string.Empty;
1251+
if (string.IsNullOrEmpty(userName))
1252+
{
1253+
return null;
1254+
}
1255+
1256+
return GetUserByUserName(portalId, userName);
1257+
}
1258+
12291259
/// -----------------------------------------------------------------------------
12301260
/// <summary>
12311261
/// GetUserCountByPortal gets the number of users in the portal

DNN Platform/Library/Security/Membership/MembershipProvider.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ public virtual UserInfo GetUserByPasswordResetToken(int portalId, string resetTo
119119
return null;
120120
}
121121

122+
public virtual string GetProviderUserKey(UserInfo user)
123+
{
124+
return null;
125+
}
126+
127+
public virtual UserInfo GetUserByProviderUserKey(int portalId, string providerUserKey)
128+
{
129+
return null;
130+
}
131+
122132
public virtual ArrayList GetUsers(int portalId, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
123133
{
124134
throw new NotImplementedException();

0 commit comments

Comments
 (0)