I have a need to periodically confirm the identity of a Member per login session. I was going to make my own db field and populate it with a random string on login, but securityStampToken does exactly that already - awesome!
Given a username and securityStampToken from an untrusworthy source I want to confirm that the securityStampToken matches the LoginName provided. However I'm having a hell of a time obtaining the securityStampToken.
Not sure it matters, but this is with Umbraco 11
private IMember? GetMemberFromToken(string token)
{
using var scope = _scopeProvider.CreateScope();
var member = scope.Database.FirstOrDefault<cmsMember>(
"SELECT [LoginName],[securityStampToken] " +
"FROM cmsMember WHERE [securityStampToken] = '@0'", token);
scope.Complete();
return member != null ? _memberService.GetByUsername(member.LoginName) : null;
}
public class cmsMember
{
public string LoginName { get; set; }
public string securityStampToken { get; set; }
}
seems no matter what I try var member is always null. Can anyone advise what I'm doing wrong?
Querying the cmsMember table
I have a need to periodically confirm the identity of a Member per login session. I was going to make my own db field and populate it with a random string on login, but securityStampToken does exactly that already - awesome!
Given a username and securityStampToken from an untrusworthy source I want to confirm that the securityStampToken matches the LoginName provided. However I'm having a hell of a time obtaining the securityStampToken.
Not sure it matters, but this is with Umbraco 11
seems no matter what I try
var memberis always null. Can anyone advise what I'm doing wrong?Hi milkman,
Your problem is here
It does not need the single quotes, npoco adds them because token is a string, so just use
Thank you so much! Your solution fixed it!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.