locked
PASSWORD CHANGING? RRS feed

  • Question

  • I need to add an option of Changing Password in a simple one file and one form based Win Form Application. Any advice/guidance in this regard other than using a single CONST PW in the code being unable to be changed later on?

    Thanx in advance.


    Best Regards, Faraz A Qureshi
    Thursday, December 1, 2011 1:48 PM

Answers

  • In VS with your project open, in the menu bar, go to Project > [your project name] properties...

    When the project property tab open, click on its Settings tab and add a setting there. Give it a name, select type string, scope user and a default value if desired. Save and close the project property tab.

    Now in code, when you want to read this setting, you do:

    Dim myvar as string = My.Settings.[the name of the setting you just added]

    When you want to set it to some other value, you do:

    My.Settings.[the name of the setting you just added] = "the new value here"

    When you want to save it after changing the value, you do:

    My.Settings.Save()

    That's the basic of it. Note that the scope must be set to User. If you set the scope to Application, you will not be able to change the value without additional efforts.

    Thursday, December 1, 2011 7:50 PM

All replies

  • With a CONST variable, its value can't be changed after declaration. You may want to look into some other ways to store the password. A simple way is to encrypt it and then store it in My.Settings. The use of some irreversible hash algorithm such as MD5 or SHA is recommended.
    Thursday, December 1, 2011 6:13 PM
  • Thanx for the reply Stanav,

    Obviously a COST remains to be CONSTANT but being new to VB a sample of code piece would be appreciated as to how to access/use my.settings.

    Thanx again.


    Best Regards, Faraz A Qureshi
    Thursday, December 1, 2011 7:27 PM
  • In VS with your project open, in the menu bar, go to Project > [your project name] properties...

    When the project property tab open, click on its Settings tab and add a setting there. Give it a name, select type string, scope user and a default value if desired. Save and close the project property tab.

    Now in code, when you want to read this setting, you do:

    Dim myvar as string = My.Settings.[the name of the setting you just added]

    When you want to set it to some other value, you do:

    My.Settings.[the name of the setting you just added] = "the new value here"

    When you want to save it after changing the value, you do:

    My.Settings.Save()

    That's the basic of it. Note that the scope must be set to User. If you set the scope to Application, you will not be able to change the value without additional efforts.

    Thursday, December 1, 2011 7:50 PM