How to enable authentication in OSPF?

There are two ways of authentication in OSPF.

1) Clear text authentication
2) MD5 authentication

1) Clear text authentication

Area based authentication

Cisco_Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Cisco_Router(config)#interface f0/0
Cisco_Router(config-if)#ip ospf authentication-key cisco@123
Cisco_Router(config-if)#exit
Cisco_Router(config)#router ospf 100
Cisco_Router(config-router)#area 2 authentication
Cisco_Router(config-router)#exit

Interface based authentication

Cisco_Router(config)#int fa0/0
Cisco_Router(config-if)#ip ospf authentication
Cisco_Router(config-if)#ip ospf authentication-key cisco
Cisco_Router(config-if)#exit


2) MD5 authentication

Area based authentication

Cisco_Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Cisco_Router(config)#interface fa0/0
Cisco_Router(config-if)#ip ospf message-digest-key 1 md5 cisco@123
Cisco_Router(config-if)#exit
Cisco_Router(config)#router ospf 100
Cisco_Router(config-router)#area 2 authentication message-digest
Cisco_Router(config-router)#exit

Interface based authentication

Cisco_Router(config)#int fa0/0
Cisco_Router(config-if)#ip ospf authentication message-digest
Cisco_Router(config-if)#ip ospf message-digest-key 1 md5 cisco
Cisco_Router(config-if)#exit