One way, or another, the password will have to stay in memory for you to use it (you can store some AES passwords in the CPU, i forgot how the technology is called, but otherwise, either it's in the memory, or you prompt the user every time to reenter it and then wipe it).
If you want to dump your whole memory, you can use memdump, but watch out, since writing it to disk uses memory too, so you might be overwriting it before you dump that part :) (Of course, if your script/program is still running, that part of the memory is stil 'used', so it wont get overwritten)
You can then try grepping the dump for your password, and it will be there (probably more then once). Finding out where the password is stored (and what it is), if you don't know it, is a lot harder task.
You can also try reading this - the page seems to be down at the moment, but google still has it cached.