Mac computers running OS X Yosemite can be locked in two ways. Use the Login Options pane in the Mac's System Preferences window to lock the computer at startup. Use the Security & Privacy pane in System Preferences to lock the Mac whenever it goes to sleep.
Locking a Mac Computer at Startup
Disabling automatic login means your Mac is locked at startup until a potential user enters a valid account password. To disable automatic login, click the "Apple" logo at the top of the Mac screen, select "System Preferences," choose "Users & Groups" and then click "Login Options." You may need to click the "Lock" icon in the bottom corner of the window and enter your password at this point to gain access to this screen. Click the "Automatic Login" drop-down menu and select "Off." Click the "Lock" icon again in the bottom corner to apply your changes.
Locking a Mac Computer After it Goes to Sleep
You can also enable locking after your Mac goes to sleep. With this feature enabled, when someone attempts to wake the Mac and resume using it, they must enter a valid account password. To enable this feature, click the "Apple" menu at the top of the Mac screen and select "System Preferences." Choose "Security & Privacy" and then select the "General" tab. You may need to click the "Lock" icon in the bottom corner of the window and enter your administrator password. Place a check mark in the "Require password" check box and select "Immediately" on the drop-down menu.