Storing a password

Is there a simple, concise way of storing a password?

I’m envisioning something like:

SaveThePassword(“BigSECRET1234”); //store in flash for later recall


nustring=ReadThePassword(); // recover the previously stored password

I’ve been looking into several ideas, but run into storing classes, making something serializable??, various notions of booting, using debuggers, “rcovering”,persisting, needing flushes, etc…is it really that complicated?

There is no out of the box method to do this. You need to break it down to separate steps: encodin/hashing, saving, retrieving, decoding (if encoded rather than hashed). This is not complicated and gives you more flexibility.

  1. To covert your string to bytes use Encoding.UTF8.GetBytes() method:

  1. If you want to hash the password, see this thread on how to do MD5 (this is built in when using .NET MF 4.2 that is coming soon to GHI products)

  1. If you want to encode/decode the password rather than hash it you can use RSA (available on EMX/Cobra)

  1. For saving, restoring use e.g. InternalFlashStorage

You just need to write your own SaveThePassword() method and then you can use it (It should be less than 10 LOC).

on the EMX devices you want to use EWR to store the password. internal flash is only on usbizi devices.

I am not interested in any encryptiion, hashing, etc, as said, I am interested in how to STORE and reacall the password in a simple concise manner probably using EWR.

[quote]I’m envisioning something like:

SaveThePassword(“BigSECRET1234”); //store in flash for later recall[/quote]

Then all you need is write methods which write/read to/from ExtendedWeakReference.

[quote]Then all you need is write methods which write/read to/from ExtendedWeakReference

Yes Yes EWR…that was known from the beginning…Do you have a simple concise example of what I referred to?

There is a good example that comes with MS MF 4.1. Check your user documents area.

This is helpful, however it leaves a lot of questions unanswered since there is not much detail offered:

If I have a value to store (password, calibration value, or other user entry), can I store it over & over as the user makes adjustments (that is does the old values just get overwritten), such that I can read the last settings after the next powerup (boot?). Or, is there some sort of erase command/procedure that is needed? Most Flash is erased in some sort of block arrangement, with a minimum size required. If so, what is that size? Can information be appended incrememtally without erasing/rewiring previous values (such as a list of time stamps)?

I was thinking of being able to specify the location to be read or written, so it could be controlled by the program:

storeValue(int value, int location)
readValue(int location)

does that make sense?


There is no append method. You have to rewrite the whole object.

So @ Mike, just to confirm-- no erase is needed, it is taken care of automatically each time the program does a store?

I guess rewriting the whole thing is not really a problem, since you can read the values out first at any time before appending (writing the whole new dataset).

Well, actually this DOES seem to be a problem…say you need to log 50000 bytes over 2 days, then that would mean byte #1 would be rewritten 50000 times & put a lot of wear on that location…I’d think there would be a way to write to a specific block of flash storage.

@ Hoty: Maybe Im missunderstand you but as Im read you look something to store password and not log file, right? For storing/reading password you can use EWR because you don’t change it every hour. EWR have limited write cycles and if you will write a lot you will damage your EMX module. For loging you can use BatteryRAM or SDCARD. The available size for BatteryRAM on EMX is 2 KB. They ONLY can be accessed (read/write) as 4 bytes multiple (starting address, offset and size). More info you can find on GHI Electronics NETMF Library.

Please demonstate how that can be done, if its easy. I’ve used the PICs and you can erase & program things into the internal flash quite easily. Just specify the block to erase & then write whatever you want to it & reead at any time desired.

Haven’t we been here before?

The API is documented at

The sample is at
c:\users<you>\My Documents\Microsoft .NET Micro Framework 4.1\Samples\ExtendedWeakReferences

You can’t expect everyone here to do your homework for you.

I want to be honest here.

Hoyt, I hardly remember you ever say thank you to people who are trying to help you. A good example is reply from Gralin above. He went some way to provide such a detailed answer. All he got back is that you are not interested in all that extra info. If you are not interested than just keep it yourself.

The more I see from you, the less I want to help.

Here is an example on how to use EWR:

I do appreciate any help I can glean. In the case of Granlin, the response had little to do with my primary objective, storing a value & then being able to read it back later. Password was just a simple example, could be voltage trip point, or any other setting to be stored. In fact, it suggested I use a method that would not work for Cobra. I already assumed EWR from early on, but the expalnations, samples, etc are seem rather poor, otherwise I would not have posted a question in the first place. There are many other posts where EWR seems to be quite a tricky topic, often not working.

I’m not sure why there seems to be a lot centered around “booting”…I could care less about that… I expect to read the values into the program IF & as I need to use them.(sometime after a power cycle)…is that possible?

In PICs you can erase a block of the flash & store values in there…later read them out, or store at additional flash block locations if more storage is needed. If this is not possible with EWR (they don’t seem to address or discuss this), is there some alternative to doing so, even with RLP routines?

I don’t think the links supplied directly answer these questions, maybe I may have to add a memory chip.

Your questions have been answered, but not in a form that you seem to be expecting.

Use EWR for your functionality. Look at the Microsoft example. And you need to rewrite to updated.

The documentation talks about power up/down options.

What more do you need?

Its not clear how the EWR data is read (don’t see any sort of read routine in the sample), it appears that everything is simply loaded back at bootup. I do see a recover method in the API, is that essentially used to verify that data is written correctly (if read does not match then write again? Or perhaps the write automatically does a verify?

As far as writing, is it possible to write to only a single block location (it appears not), but this would be used to wear level—if there are 1000 storage locations you could then spread the writes around. However, if they must always ALL be written, then that is not possible.