How can I display a message after login? When a user logs in, I want to display the message "Login Success" or an error message "Username or Password is incorrect" if a user enters the wrong details. 

What is the best method for displaying these messages when a user logs in and logs out? I am not sure how to write the correct way using getFlash?
You can achieve this using a plugin and the UserSessionService.

craft()-&gt;on( 'userSession.onLogin', function( Event $event ){
  // Sets the flash message on log in
  craft()-&gt;userSession-&gt;setFlash( 'message', "You've been logged in" );
});

craft()-&gt;on( 'userSession.onLogout', function( Event $event ){
  // Sets the flash message on log out
  craft()-&gt;userSession-&gt;setFlash( 'message', "You've been logged out" );
});


And then in your template you can see of a flash message exists and print it out.

{% set message = craft.session.getFlash( 'message' ) %}

{% if message %}
  {{ message }}
{% endif %}


The message for the incorrect login details will be handled by Crafts login controller. Take a look at the example front end log in page in the docs to see how this is handled.