Centralizing data that is meant to be reused across an application is a standard design pattern. Let's say you have a group of web pages on top of which you wanna display the name of the user, or you need to cache the posts or profile of a particular user. Different frameworks provide different tools for this purpose, for instance in Vue.js
, Vuex
is offered to implement this mechanism.
In case of your question, you have not specified which framework you are using, whether it is ASP.Net
, WPF
, or even a pure C#
application relying on OWIN
. But yet no issues, there are a few ways that can allow you to achieve what you are after and you can chose whichever best suites your needs:
1- You can develop a cache layer in your app, and cache the password or other data through the lifecyle of a particular session. To do this, you can either rely on a "Concurrent Collection" or you can make use an EF Core In-Memory database. (IMemeoryCache
is also available in ASP.Net Core)
2- In case the password is meant to undergo some interops, then I recommend you to go for a global cache server. To do so, you can use Redis or Alachisoft NCache.
3- In case that is a web application, then you can preserve the data in a cookie or the local storage of browser.
Keep in mind, the SecureString
may not give you any security advantage as you expect with respect to the fact that as stated by Microsoft:
A SecureString object is similar to a String object in that it has a text value. However, the value of a SecureString object is pinned in memory, may use a protection mechanism, such as encryption, provided by the underlying operating system, can be modified until your application marks it as read-only, and can be deleted from computer memory either by your application calling the Dispose method or by the .NET Framework garbage collector.
That said; you have to look at the security aspect of this type from the perspective of memory and memory management. Finally, you have to implement your own security provider, such as hash generation or encryption in other achieve real security.