यह प्रश्न @sharptooth द्वारा this related question में किए गए एक सुझाव का पालन करता है।पासवर्ड-सुरक्षित कक्षा कैसे लिखें?
std::string
tweaked किया जा सकता है ताकि यह पासवर्ड-सुरक्षित हो जाए?
यदि नहीं, तो पासवर्ड-हैंडलिंग क्लास लिखने के दिशानिर्देश क्या होंगे (इस प्रकार एक वर्ग जो स्मृति के बारे में बड़ी देखभाल करता है और विनाश से पहले इसे साफ़ करता है)?
template <class T> class SecureAllocator : public std::allocator<T>
{
public:
template<class U> struct rebind { typedef SecureAllocator<U> other; };
SecureAllocator() throw() {}
SecureAllocator(const SecureAllocator&) throw() {}
template <class U> SecureAllocator(const SecureAllocator<U>&) throw() {}
void deallocate(pointer p, size_type n)
{
std::fill_n((volatile char*)p, n*sizeof(T), 0);
std::allocator<T>::deallocate(p, n);
}
};
यह संभाजक deallocating से पहले स्मृति शून्य:
1) std: wstring, 2) पासवर्ड प्रतीकों के बजाय 0x2022 पुश करें: ओ) गंभीरता से, अगर आपको डर है कि अन्य प्रक्रिया आपकी याददाश्त से कुछ छीनती है, तो इसमें कुछ मुखौटा जोड़ें/हटाएं (xor?) – alxx
@alxx : 'Std :: string' के बजाय' std :: wstring' का उपयोग कैसे सुरक्षित होगा? क्या मैं कुछ भूल रहा हूँ ? – ereOn
0x2022 बुलेट प्रतीक है। उसे ले लो? :) – alxx