Home > database >  C# Changing Resources at Runtime
C# Changing Resources at Runtime

Time:02-18

I am trying to save the username and password of user at c# console application. Hence there will be just one username and password that must be saved (It is like pin code). I don't want to use a Database for this. Using .txt will be irrational because anyone can see and find txt file and enter program.

I tried to use Properties.Resources but because of Resources are read-only, there is no way of changing password at runtime if user wants to change its password.

     Properties.Resources.Admin_Mail = Reading;

It gives error because of the reason I mentioned above.

What should I use, I cannot find any suitable way for this problem on the internet.

CodePudding user response:

I am not sure where you are at in your development journey.

You'll need system.io to read and write to the text file. I would give in a different extension then .txt. https://docs.microsoft.com/en-us/dotnet/api/system.io?view=net-6.0

Consider using a SecureString type in C# https://docs.microsoft.com/en-us/dotnet/api/system.security.securestring?view=net-6.0

Encrypt the data stored in the file. https://docs.microsoft.com/en-us/dotnet/standard/security/encrypting-data

Decrypt the users entry to ensure it matches the file. https://docs.microsoft.com/en-us/dotnet/standard/security/decrypting-data

There is a StackOverFlow link talking at the actually input. Password masking console application

Sorry for just linking to references instead of a straightforward code answer, but I not sure of your intent and level of security you wish to provide.

  •  Tags:  
  • c#
  • Related