improved password handling

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13965 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2005-08-17 14:31:28 +00:00
parent 3406dc829e
commit 0b0923357e
4 changed files with 29 additions and 19 deletions
+4 -3
View File
@@ -21,16 +21,17 @@ PasswordWindow::Setup()
BRect bounds(fBgd->Bounds()); BRect bounds(fBgd->Bounds());
bounds.InsetBy(5,5); bounds.InsetBy(5,5);
fCustomBox = new BBox(bounds,"custBeBox",B_FOLLOW_NONE); fCustomBox = new BBox(bounds, "custBeBox", B_FOLLOW_NONE);
fCustomBox->SetLabel("Unlock screen saver"); fCustomBox->SetLabel("Unlock screen saver");
fBgd->AddChild(fCustomBox); fBgd->AddChild(fCustomBox);
fPassword = new BTextControl(BRect(10,28,255,47),"pwdCntrl","Enter fPassword:",NULL,B_FOLLOW_NONE); fPassword = new BTextControl(BRect(10,28,255,47),"pwdCntrl","Enter password:", NULL, B_FOLLOW_NONE);
fPassword->TextView()->HideTyping(true);
fPassword->SetDivider(100); fPassword->SetDivider(100);
fCustomBox->AddChild(fPassword); fCustomBox->AddChild(fPassword);
fUnlock = new BButton(BRect(160,70,255,85), "fUnlock", "Unlock", new BMessage(UNLOCK_MESSAGE), B_FOLLOW_NONE); fUnlock = new BButton(BRect(160,70,255,85), "fUnlock", "Unlock", new BMessage(UNLOCK_MESSAGE), B_FOLLOW_NONE);
fUnlock->SetTarget(NULL,be_app); fUnlock->SetTarget(NULL, be_app);
fCustomBox->AddChild(fUnlock); fCustomBox->AddChild(fUnlock);
fUnlock->MakeDefault(true); fUnlock->MakeDefault(true);
} }
+1 -2
View File
@@ -21,12 +21,11 @@ SSAwindow::SSAwindow(BRect frame)
SSAwindow::~SSAwindow() SSAwindow::~SSAwindow()
{ {
Hide(); Hide();
// Sync();
} }
bool bool
SSAwindow::QuitRequested(void) SSAwindow::QuitRequested()
{ {
return true; return true;
} }
+23 -12
View File
@@ -3,6 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <Debug.h>
#include <stdio.h> #include <stdio.h>
#include <Screen.h> #include <Screen.h>
#include <image.h> #include <image.h>
@@ -36,7 +37,7 @@ ScreenSaverApp::ScreenSaverApp()
void void
ScreenSaverApp::ReadyToRun(void) ScreenSaverApp::ReadyToRun()
{ {
if (!fPref.LoadSettings()) if (!fPref.LoadSettings())
exit(1); exit(1);
@@ -44,7 +45,7 @@ ScreenSaverApp::ReadyToRun(void)
BScreen theScreen(B_MAIN_SCREEN_ID); BScreen theScreen(B_MAIN_SCREEN_ID);
fWin = new SSAwindow(theScreen.Frame()); fWin = new SSAwindow(theScreen.Frame());
fPww = new PasswordWindow(); fPww = new PasswordWindow();
fThrd = new ScreenSaverThread(fWin,fWin->fView,&fPref); fThrd = new ScreenSaverThread(fWin ,fWin->fView, &fPref);
fSaver = fThrd->LoadAddOn(); fSaver = fThrd->LoadAddOn();
if (!fSaver) if (!fSaver)
@@ -52,7 +53,7 @@ ScreenSaverApp::ReadyToRun(void)
fWin->SetSaver(fSaver); fWin->SetSaver(fSaver);
fWin->SetFullScreen(true); fWin->SetFullScreen(true);
fWin->Show(); fWin->Show();
fThreadID = spawn_thread(ScreenSaverThread::ThreadFunc,"ScreenSaverRenderer",0,fThrd); fThreadID = spawn_thread(ScreenSaverThread::ThreadFunc,"ScreenSaverRenderer", B_LOW_PRIORITY,fThrd);
resume_thread(fThreadID); resume_thread(fThreadID);
HideCursor(); HideCursor();
} }
@@ -60,7 +61,7 @@ ScreenSaverApp::ReadyToRun(void)
void void
ScreenSaverApp::ShowPW(void) ScreenSaverApp::ShowPW()
{ {
fWin->Lock(); fWin->Lock();
suspend_thread(fThreadID); suspend_thread(fThreadID);
@@ -79,7 +80,10 @@ ScreenSaverApp::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch(message->what) {
case UNLOCK_MESSAGE: case UNLOCK_MESSAGE:
if (strcmp(fPww->GetPassword(),fPref.Password())) { {
char salt[3] = "";
strncpy(salt, fPref.Password(), 2);
if (strcmp(crypt(fPww->GetPassword(), salt),fPref.Password())) {
beep(); beep();
fPww->Hide(); fPww->Hide();
fWin->SetFullScreen(true); fWin->SetFullScreen(true);
@@ -87,16 +91,11 @@ ScreenSaverApp::MessageReceived(BMessage *message)
resume_thread(fThreadID); resume_thread(fThreadID);
} }
else { else {
printf ("Quitting!\n"); PRINT(("Quitting!\n"));
Shutdown(); Shutdown();
} }
break; break;
case 'MOO1': }
if (real_time_clock()-fBlankTime>fPref.PasswordTime())
ShowPW();
else
Shutdown();
break;
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; break;
@@ -104,6 +103,18 @@ ScreenSaverApp::MessageReceived(BMessage *message)
} }
bool
ScreenSaverApp::QuitRequested()
{
if (system_time()-fBlankTime>fPref.PasswordTime()) {
ShowPW();
return false;
} else
Shutdown();
return BApplication::QuitRequested();
}
void void
ScreenSaverApp::Shutdown(void) ScreenSaverApp::Shutdown(void)
{ {
+1 -2
View File
@@ -18,8 +18,7 @@ public:
ScreenSaverApp(); ScreenSaverApp();
bool LoadAddOn(); bool LoadAddOn();
void ReadyToRun(); void ReadyToRun();
// bool QuitRequested(); virtual bool QuitRequested();
// void Quit();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
void ShowPW(); void ShowPW();
private: private: