if conditional in sidebar plugin Password content shortcode

Two ways you can do that,

  1. You can write a new short code for e.g [check_sumbit] and then use it in side bar, and that short should check if form is submitted correctly

  2. You can use php code as you mentioned in your question using some plugins that allow php code in widgets. For e.g.
    https://wordpress.org/plugins/php-code-widget/