I need to store a user\'s password for a short period of time in memory. How can I do so yet not have such information accidentally disclosed in coredumps or tracebacks? Is
based on culix's answer: the following works with Linux 64-bit architecture.
Tested on Debian based systems.
import sys
import ctypes
def nuke(var_to_nuke):
strlen = len(var_to_nuke)
offset = sys.getsizeof(var_to_nuke) - strlen - 1
ctypes.memset(id(var_to_nuke) + offset, 0, strlen)
del var_to_nuke # derefrencing the pointer.