This module is used to display the last login time of current logged in user.

This module stores the last login time in a session variable and pass this variable to Last login time Block. It is a lightweight module which do not create an extra table in a database. It is easy to install & use this module.

Project Page: https://www.drupal.org/project/last_login

git clone --branch 7.x-1.x https://git.drupal.org/project/last_login.git
cd last_login

Installation:

  1. Download the module and place in sites/all/modules directory.
  2. Enable the module in admin/modules.
  3. Now goto admin/structure/block.
  4. Follow only one of the both ways mentioned below:-
    • Enable the Last login time block and assign a specific region.
    • OR
    • You can directly print session variable ($_SESSION["user_last_login"]) in your template file.
  5. You need to logout and login again to see the last login time.

Manual reviews of other projects

https://www.drupal.org/node/2892934#comment-12161008
https://www.drupal.org/node/2898595#comment-12191641
https://www.drupal.org/node/2891185#comment-12199766

CommentFileSizeAuthor
#15 last_login.patch674 bytesCyclonecode

Comments

munishsharma created an issue. See original summary.

PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

munish.kumar’s picture

Issue summary: View changes
Aaron23’s picture

Hi,
I have reviewed this module. Works good..! and also checked pa review, there are no errors

Thanks

eliechoufani’s picture

Hello, after my review and tests, this module was checked and has no errors.

Thank you.

moinak_dutta’s picture

Hi munishsharma,

Automated Review

[Best practice issues identified by pareview.sh]

Manual Review

Individual user account
[Yes: Follows] the guidelines for individual user accounts.

No duplication
[Yes: Does not cause] module duplication and/or fragmentation.

Master Branch
[Yes: Follows] the guidelines for master branch.

Licensing
[Yes: Follows] the licensing requirements.

3rd party assets/code
[Yes: Follows] the guidelines for 3rd party assets/code.

README.txt/README.md
[Yes: Follows] the guidelines for in-project documentation and/or the README Template.

Code long/complex enough for review
[No: Does not follow] the guidelines for project length and complexity.

Secure code
[No: List of security issues identified.]

If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.

shashikant_chauhan’s picture

Status: Needs review » Needs work

Hi,

Can you specify why you are using hook_form_alter. You have added custom form validation but not validating anything. You are just setting the $_SESSION['user_last_login'] variable. The better way is use of hook_user_login

shashikant_chauhan’s picture

Status: Needs work » Needs review
munish.kumar’s picture

Hi Shashikant,

Thanks, for reviewing this module. I am using hook_form_alter in this module because I have to fetch the last login time of the user from a database. In hook_user_login we always get the current login time that means the last login time is updated before hook_user_login invokes. It is a lightweight version so I used hook_form_alter and in the validate function I fetch the login time before it gets updated and stores it into a session variable.

shashikant_chauhan’s picture

Thanks, Munish for explaination. Your module looks good to go. +1 from me.

sharma.amitt16’s picture

Hello,

I reviewed the module and found no errors. It works perfectly for me. +1 from me.

Good idea to display user last login time...

flashwebcenter’s picture

Hello munishsharma,
Nice module +1, I am sure it will be useful for drupal community. It is light weight and easy to use. I tested the module and everything is working good.

munish.kumar’s picture

Issue summary: View changes
munish.kumar’s picture

Issue summary: View changes
Issue tags: +PAreview: review bonus
Cyclonecode’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new674 bytes

Nice module. It seems to work fine and the code looks good. The only thing I found was a couple of small issues regarding global variable placement and translation. I added a very small patch to resolve these issues. Aside from this I don't see any reason not to mark this as RTBC.

Automated Review

Pareview does not report any error or warnings.

Manual Review

Individual user account
Yes: Follows
No duplication
Yes: Does not cause
Master Branch
Yes: Follows
Licensing
Yes: Follows
3rd party assets/code
Yes: Follows
README.txt/README.md
Yes: Follows
Code long/complex enough for review
Yes: Follows
Secure code
Yes: Follows
Coding style & Drupal API usage
(*) Major finding, needs work
(+) Release blocker
Rekommendations:
1. I would keep any global and static variables used at the top of each function.
2. Added a patch for untranslated string in block content.

munish.kumar’s picture

Hi @Cyclonecode,

Thanks, for reviewing this module, I have already applied this patch in my latest release. Any Update for +RTBC ?

th_tushar’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +PAreview: security, +PAreview: single application approval

There is a security finding in the module's code.

$content = isset($_SESSION['user_last_login']) ? '<div class="last-access">' . $label . ' : ' . $_SESSION['user_last_login'] . '</div>' : '';

Please go through the https://www.drupal.org/docs/7/security/writing-secure-code/handle-text-in-a-secure-fashion to handle the text in secure fashion.

munish.kumar’s picture

Hi th_tushar,

Thanks for the review, I have go through the link provided by you,
As I understand that to store the text in such a way exactly what the user typed. But in the line below there is no user typed content:
$content = isset($_SESSION['user_last_login']) ? '<div class="last-access">' . $label . ' : ' . $_SESSION['user_last_login'] . '</div>' : '';

I have store a value to a variable $content. In the module file you can see that $label is defined right above this line and it is not user typed text(only a string). Could you please explain this security finding to me more precisely so that I can fix this.

th_tushar’s picture

Hi @munishsharma,

Please use check_plain() function to print the session variable as it can be changed/updated with any malicious code.

Thanks!

munish.kumar’s picture

Hi th_tushar,

I think that is the separate case you are talking about. Please correct me If I am wrong, If I use check_plain() function to print the session variable, how can you say that this variable cannot be changed/updated with any malicious code?. If any malicious activity have access to the session variable, then the variable also updated/changed whether we use check_plain() or not. However, if we create our own module that collects user inputs without passing it through a "safe" text filter such as "Plain", we must use this function for sanitation purposes. In this module I do not collect any input from user, So I think there is no need to add this function.
What do you suggest.?

Cyclonecode’s picture

I do not see any reason not to use check_plain() to process the session variables? In my opinion it would not hurt.

shashwat purav’s picture

Issue tags: +DrupalMumbaiCodeSprint

Assigning this issue for Drupal Mumbai Code Sprint Dec 2017.

PA robot’s picture

Status: Needs work » Closed (won't fix)

Closing due to lack of activity. If you are still working on this application, you should fix all known problems and then set the status to "Needs review". (See also the project application workflow).

I'm a robot and this is an automated message from Project Applications Scraper.

munish.kumar’s picture

Status: Closed (won't fix) » Needs review
avpaderno’s picture

/**
 * Implements hook_block_view().
 */
function last_login_block_view($delta = '') {
  $block = array();
  global $user;
  $label = t('Last Login');
  $content = isset($_SESSION['user_last_login']) ? '<div class="last-access">' . $label . ' : ' . $_SESSION['user_last_login'] . '</div>' : '';

  switch ($delta) {
    case 'last_login_block':
      if ($user->uid) {
        $block['content'] = $content;
      }
      else {
        $block['content'] = '';
      }
      break;
  }

  return $block;
}

check_plain() should be used when outputting a value that is supposed not to contain HTML markup, but as Writing secure code says, it should be used on user-submitted content. It is true the code I am showing could output <script src="http://malicious.site.com/crack.js" /> if a malicious module alter the value of $_SESSION['user_last_login'], but in that case the malicious code could do worse things.

In short, the code used from the module and that I shown is correctly not using check_plain() because it is not outputting any user-submitted value.

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Fixed
Issue tags: -PAreview: security, -PAreview: single application approval, -DrupalMumbaiCodeSprint

Thank you for your contribution!
I am going to update your account so you can opt into security advisory coverage now.
These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank all the dedicated reviewers as well.

munish.kumar’s picture

Thanks @kiamlaluno, for updating my account.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.