I am not sure why we should solve this with custom code, I apologies, if I do miss something, Please let me know.
Maybe my previous instructions where to broad, so I reformulated it.
The Goal:
Display a success message after successful login.
The Best Solution with Toolset for this is (can be):
1. insert the Login Form ShortCode to a page (any-page)
2. pass the same page's full URL (site.com/any-page), with a Search parameter added to the URL, to the `redirect_url` attribute of the Login Form ShortCode (this is used when the login is successful)
Example:
[wpv-login-form redirect_url="[wpv-bloginfo show="url"]/any-page/?success=yes"]
Of course, you need to replace "any-page" with the real slug of your page where the login form is.
==> Now, when the visitor logs in, and the login is correct, it will lead to that exact URL (site.com/any-page/?success=yes)
3. On the same page where you display this login form, display your success message - conditionally, using Conditional HTML ShortCodes available in Toolset:
[wpv-conditional if="( '[wpv-search-term param="success"]' eq 'yes' )"]
yes! PUT THE MESSAGE HERE
[/wpv-conditional]
We are listening to the Search parameter - which is the ?success=yes part.
If that is yes, then we display the message, otherwise not.
The filter requested for this is not required, it could not even solve the goal.
The code shared by Minesh is restricting access to a page, in particular, I am not sure as well why that should be done with Custom Code, as to hide or not allow access to pages we do use Toolset Access, however, that is not even the topic here.
Please, let me know if anything is unclear.
The steps shown above will do exactly what you require.
It will show a Login Form, and upon successful login a success message.
Usually we do that on a specific page, hence, we do not display the "success message" directly on the login page but redirect somewhere else.
This because otherwise when the user is logged in, he will always see the success message.
It depends a lot here on what the content of your messages are.
Please let me know if this works for you - otherwise I can set up a dummy test for you on the site.
But the steps above should lead to the exact desired outcome.