Xander
Xander

Reputation: 9171

UserNamePasswordValidator and caching results

I have a UserNamePasswordValidator and it hits a database to verify that the request is valid for the wcfclientcredentials.

I came to realize that I don't want to hit the database everytime I make a call.

What is the best way to cache the results?

ie if I already know username/pass is valid why check it over and over again?

Upvotes: 0

Views: 296

Answers (2)

Haris Hasan
Haris Hasan

Reputation: 30097

Although I agree with mellamokb's comment but if you really wana do it...

I would go for Dictionary<UserName, SecureString>

Plus you will have to make sure that you update the dictionary in case of password change

Upvotes: 2

FIre Panda
FIre Panda

Reputation: 6637

You could cache the username/password in a dictionary with username as the key and password as the value.

Dictionary<string, string> userName_Pwd_Cache = new Dictionary<string, string>();
//caching username/password code

    if(userName_Pwd_Cache.ContainsKey(userNameVar)) //let userNameVar is entered username
    {
           if(userName_Pwd_Cache[userNameVar] == passwordVar) //let passwordVar is entered passwords
           {
               //user authenticated
           }
           else
           {
               //authentication failed 
           }
    }

Upvotes: 1

Related Questions