Passed
Push — master ( 004729...b97da3 )
by Tim
02:36
created

Random::generateOneTimePassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Random utilities for SMS-based OTP.
5
 *
6
 * @package tvdijen/simplesamlphp-module-cmdotcom
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimpleSAML\Module\cmdotcom\Utils;
12
13
class Random
14
{
15
    /**
16
     * Generate a 6-digit random code
17
     *
18
     * @return string
19
     */
20
    public function generateOneTimePassword(): string
21
    {
22
        $code = sprintf("%06d", mt_rand(10000, 999999));
23
        $padded = str_pad($code, 6, '0', STR_PAD_LEFT);
24
25
        return $padded;
26
    }
27
}
28