If your Mac is in an open area or you just want to make sure curious eyes don't have easy access to your computer, you can use the built-in Mac OS X Screen Saver with password protection to secure your Mac.
First, pick a Screen Saver
Open System Preferences (in the Apple menu) and then click the Desktop & Screen Saver icon in the top row.
Click on the Screen Saver tab to show its settings. You'll see a list of screen savers in the left column. Pick one.
Next, choose a Hot Corner.
While still in Screen Saver settings, click the button, "Hot Corners..." Hot Corners lets you set an action that will be performed when the mouse pointer is moved into a corner of the Mac screen. For one of the four corners , select "Start Screen Saver" from the pop-up menu and then click OK. In the screenshot below, the top-right corner will start the screen saver.
Finally, require a password.
Before you perform this step, make sure you know your password.
Click the "Show All" button (in the top left corner of the settings window) to show all System Preferences. Then, click the Security icon in the top row.
In the General tab of Security settings, click to check the setting, "Require password immediately after sleep or screen saver begins." In place of "immediately" you can specify a different duration. (Note: the duration setting is available in Mac OS X v10.6 Snow Leopard and later.)
Lock Your Mac
Now, when you move the mouse pointer into the corner you had set, the screen saver will activate. To gain access to your Mac, move the mouse. A login window will open, requiring a password. Enter your password to dismiss the screen saver and gain access to your Mac.