UltraScan III
us_passwd.cpp
Go to the documentation of this file.
1 #include "us_passwd.h"
3 #include "us_settings.h"
4 #include "us_global.h"
5 
6 QString US_Passwd::getPasswd( void )
7 {
8  // If the pw is in global memory, return it
9  QString pw = g.passwd();
10  if ( ! pw.isEmpty() ) return pw;
11 
12  // See if the master pasword has been set
13  QByteArray currentHash = US_Settings::UltraScanPW();
14 
15  if ( currentHash.isEmpty() )
16  {
17  QMessageBox::information( this,
18  tr( "Password Error" ),
19  tr( "The Master Password has not been set." ) );
20 
21  return QString();
22  }
23 
24  // Ask the user to input the password
25  while ( true )
26  {
27  bool ok;
28  pw = QInputDialog::getText(
29  this,
30  tr( "Master Password" ),
31  tr( "Please input your Master Password" ),
32  QLineEdit::Password,
33  QString(),
34  &ok );
35 
36  // If the user cancelled, return a null string
37  if ( ! ok ) return QString();
38 
39  // Check the hash
40  QByteArray hash =
41  QCryptographicHash::hash( pw.toAscii(), QCryptographicHash::Sha1 );
42 
43  if ( hash == currentHash ) break;
44 
45  QMessageBox::information( this,
46  tr( "Password Error" ),
47  tr( "The password is incorrect." ) );
48  }
49 
50  // Save the password in global memory and return
51  g.setPasswd( pw );
52  return pw;
53 }
54 
55