Disclosure of Invention
To overcome the problems in the related art, the present invention provides a method and an apparatus for generating a password of a target event.
According to a first aspect of embodiments of the present invention, there is provided a method of generating a password for a target event, the method including:
when a target event is triggered, acquiring a historical random number list; the historical random number list comprises random numbers corresponding to the generated passwords;
generating a target random number which is not located in the historical random number list in the first value interval;
and determining the password of the target event according to the target random number.
Further, the method further comprises:
storing the target random number in the historical random number list.
Wherein said generating a target random number not located in said historical random number list within said first value interval comprises:
generating a first interval random number within said first interval;
judging whether the first numerical interval random number is in the historical random number list or not;
and when the first numerical interval random number is not in the historical random number list, determining the first numerical interval random number as the target random number.
Further, the method further comprises:
and when the first value interval random number is positioned in the historical random number list, returning to the step of generating the first value interval random number positioned in the first value interval until the generated first value interval random number is not positioned in the historical random number list.
Further, the method further comprises:
when the first numerical interval random number is located in the historical random number list, counting the generation times of generating the first numerical interval random number in an accumulated mode;
comparing the generation times with preset times;
when the execution times are less than the preset times, returning to the step of generating a first numerical interval random number located in the first numerical interval;
and when the execution times is equal to the preset times, generating a second numerical interval reference number in a second numerical interval which is not coincident with the first numerical interval, and determining the password of the target event according to the second numerical interval reference number.
Wherein the generating a second value interval reference number comprises:
determining a reference value interval according to the difference value between the maximum value and the minimum value in the second value interval and a preset alternative value;
selecting one value from the values not selected from the reference value interval as an encryption base value;
encrypting the encryption basic value according to a preset encryption mode to obtain an encrypted value smaller than the difference value;
and adding the encrypted numerical value and the minimum numerical value in the second numerical value interval to obtain a numerical value positioned in the second numerical value interval, and using the numerical value as the reference number of the second numerical value interval.
Wherein, encrypting the encryption basic value according to a preset encryption mode comprises:
encrypting the encryption basic value according to the following formula;
C=(k1m+k2)mod n;
in the above formula, C is the encrypted numerical value, k1 is a first preset numerical value, k2 is a second preset numerical value, m is the encrypted basic numerical value, n is a third preset numerical value, and mod is a remainder operation symbol.
According to a second aspect of the embodiments of the present invention, there is provided an apparatus for generating a password of a target event, the apparatus including:
the acquisition module is used for acquiring a historical random number list when a target event is triggered; the historical random number list comprises random numbers corresponding to the generated passwords;
the generating module is used for generating a target random number which is not positioned in the historical random number list in the first numerical value interval;
and the determining module is used for determining the password of the target event according to the target random number.
Further, the apparatus further comprises:
and the storage module is used for storing the target random number into the historical random number list.
Wherein the generating module comprises:
the first generating unit is used for generating a first numerical interval random number positioned in the first numerical interval;
the judging unit is used for judging whether the first numerical interval random number is positioned in the historical random number list or not;
a determining unit, configured to determine the first value interval random number as the target random number when the first value interval random number is not located in the history random number list.
Further, the generating module further comprises:
the first generating unit is further configured to return to the step of generating a first value interval random number located in the first value interval when the first value interval random number is located in the history random number list until the generated first value interval random number is not located in the history random number list.
Further, the generating module further comprises:
the statistical unit is used for counting the generation times of generating the first numerical interval random number in an accumulated mode when the first numerical interval random number is located in the historical random number list;
the comparison unit is used for comparing the generation times with preset times;
the first generating unit is further configured to return to the step of generating a first numerical interval random number located in the first numerical interval when the execution times is less than the preset times;
and the second generating unit is used for generating a second numerical value interval reference number in a second numerical value interval which is not overlapped with the first numerical value interval when the execution times is equal to the preset times, and determining the password of the target event according to the second numerical value interval reference number.
Wherein the second generating unit includes:
the determining subunit is used for determining a reference value interval according to the difference value between the maximum value and the minimum value in the second value interval and a preset alternative value;
a selection subunit, configured to select one of the values that have not been selected from the reference value interval as an encryption base value;
the encryption subunit is used for encrypting the encryption basic value according to a preset encryption mode to obtain an encryption value smaller than the difference value;
and the adding subunit is configured to add the encrypted numerical value to the minimum numerical value in the second numerical value interval to obtain a numerical value located in the second numerical value interval, and use the numerical value as the reference number of the second numerical value interval.
The encryption subunit is specifically configured to encrypt the encryption basic value according to the following formula;
C=(k1m+k2)mod n;
in the above formula, C is the encrypted numerical value, k1 is a first preset numerical value, k2 is a second preset numerical value, m is the encrypted basic numerical value, n is a third preset numerical value, and mod is a remainder operation symbol.
The technical scheme provided by the embodiment of the invention can have the following beneficial effects: in the invention, when a target event is triggered, a historical random number list is obtained; the history random number list comprises random numbers corresponding to the generated passwords; generating a target random number which is not positioned in the historical random number list in the first numerical value interval; and determining the password of the target event according to the target random number. According to the method provided by the embodiment of the invention, a large number of different random values do not need to be generated in advance, so that more time is not occupied by the generation of a large number of different random values in advance; and a large amount of random numerical values generated in advance do not need to be stored locally; therefore, the local large storage space is not occupied.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention, as claimed.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the invention, as detailed in the appended claims.
FIG. 1 is a flow diagram illustrating a method of generating a password for a target event, as shown in FIG. 1, according to an exemplary embodiment.
In step S101, when a target event is triggered, a history random number list is acquired;
the history random number list comprises random numbers corresponding to the generated passwords;
all random numbers included in the historical random number table are values in the first value interval, and the values are randomly generated values.
In the history process, when a random number in a first value interval is generated and the password of a certain event is determined according to the generated random number, the generated random number is stored in a history random value table.
For example, assume that the historical random number list is shown in Table 1 below. The random numbers 100123, 205489, 374152, 387412, and 587412 stored in table 1 are all random numbers corresponding to passwords generated for certain events in the history.
TABLE 1
Historical random number list
|
100123
|
205489
|
374152
|
387412
|
578412 |
In step S102, a target random number not located in the history random number list is generated in the first value interval;
the target event may be an event that requires generation of an authentication code, for example, when a user wants to log in to the server, the server generates an authentication code so that the user enters the authentication code in the authentication code input box at the time of logging in.
The target event can also be an event needing to generate a password, for example, when a user registers a login account and a login password for logging in a server, if the user does not want to set the login password by himself, the server can randomly generate a login password for the user.
The first value interval may be any two different value intervals with end point values, for example, the first value interval may be 100000 and the first value interval may be 100000-899999 with end point values of 899999.
In this case, a random number that is not in the history random number list may be generated for the target event within the first value interval using an existing random algorithm, and used as the target random number.
For example, the target random number that is not in the history random number list generated in the first value interval is 213025.
In step S103, a password of the target event is determined from the target random number.
Wherein the target random number can be directly used as the password of the target event.
Further, the target random number is stored in the history random number list.
This allows the generation of a password for an event later on without the generation of the same random number corresponding to the password as the one generated for the target event.
For example, the generated random number 213025 is added to the history random number list shown in table 1, resulting in a history random number list shown in table 2.
TABLE 2
Historical random number list
|
100123
|
205489
|
374152
|
387412
|
578412
|
213025 |
In the embodiment of the invention shown in fig. 1, when a target event is triggered, a history random number list is obtained; the history random number list comprises random numbers corresponding to the generated passwords; generating a target random number which is not positioned in the historical random number list in the first numerical value interval; and determining the password of the target event according to the target random number. According to the method provided by the embodiment of the invention, a large number of different random values do not need to be generated in advance, so that more time is not occupied by the generation of a large number of different random values in advance; and a large amount of random numerical values generated in advance do not need to be stored locally; therefore, the local large storage space is not occupied.
In another embodiment of the present invention, referring to fig. 2, step S102 includes:
in step S201, a first value interval random number within a first value interval is generated;
in step S202, it is determined whether the first value interval random number is in the history random number list;
the method comprises the steps of obtaining a first random number in a history random number list, comparing the first random number with a first numerical interval random number, and determining that the first numerical interval random number is located in the history random number list if the first random number is the same as the first numerical interval random number. If the two are different, a second random number in the historical random number list is obtained, the second random number is compared with the first numerical interval random number, and if the second random number is the same as the first numerical interval random number, the first numerical interval random number is determined to be located in the historical random number list. And if the two random numbers are different, acquiring a third random number in the historical random number list, and continuing to execute the steps until the last random number in the historical random number list is acquired, if the last random number is the same as the first numerical interval random number, determining that the first numerical interval random number is positioned in the historical random number list, and if the last random number is different from the first numerical interval random number, determining that the first numerical interval random number is not positioned in the historical random number list.
When the first value range random number is not located in the history random number list, the first value range random number is determined as the target random number in step S203.
When the first value interval random number is not in the history random number list, it indicates that the password of an event is not determined according to the first value interval random number in the history process, that is, the first value interval random number is not taken as the random number corresponding to the password of the event, so that the password of the target event can be determined according to the first value interval random number.
For example, assume that the first numerical range random number generated in step S201 is 213025; if the same random number as the first value interval random number 213025 is not found in the history random number list shown in table 1, it means that the password of an event has not been determined from the first value interval random number 213025 in the history process, that is, the first value interval random number 213025 has not been taken as the random number corresponding to the password of an event, and therefore, the password of the target event can be determined from the first value interval random number 213025.
When the first value interval random number is in the history random number list, returning to step S201: generating a first range random number within a first range of values; until the generated first value interval random number is not in the history random number list.
When the first value interval random number is in the history random number list, it is described that the password of an event is determined according to the first value interval random number in the history process, that is, the first value interval random number is used as the random number corresponding to the password of the event, so that, in order to avoid that the random numbers corresponding to the passwords of a plurality of different events are the same, a first value interval random number in the first value interval needs to be generated again until the generated first value interval random number is not in the history random number list, that is, until the generated first value interval random number is not used as the random number corresponding to the password of the event in the history process, that is, until the first value interval random number is not in the history random number list. Therefore, when the first value section random number is located in the history random number list, the process returns to step S201.
For example, assume that the first numerical range random number generated in step S201 is 205489; if the first random number 100123 in the history random number list shown in table 1 is acquired, and the first random number 100123 is compared with the first value interval random number 205489, and if the first random number 100123 is different from the first value interval random number 205489, the second random number 205489 in the history random number list is acquired, and the second random number 205489 is compared with the first value interval random number 205489, and if the second random number is the same as the first value interval random number 205489, it indicates that the first value interval random number 205489 is located in the history random number list, and the step S201 is returned until the generated first value interval random number is not located in the history random number list.
In another embodiment of the present invention, referring to fig. 3, when the first value interval random number is located in the history random number list, the method further comprises the steps of:
in step S301, the number of times of generating a first numerical interval random number is counted up and accumulated;
when the target event is triggered, counting is carried out each time a first value interval random number in a first value interval is generated for the target event.
For example, when a first value interval random number within a first value interval is generated for a target event for the first time, the generation number is set to 1; if the first value interval random number generated for the first time is located in the historical random number list, a first value interval random number located in the first value interval is generated for the target event again, and the generation times 1 and the value 1 are added to obtain the generation times 2.
In step S302, the generation number is compared with a preset number;
in the embodiment shown in fig. 2 of the present invention, the password of the target event is not determined according to the generated first value interval random number until the generated first value interval random number is not located in the history random number list. Otherwise, step S201 is executed all the time: a first interval random number is generated within the first interval. However, sometimes it is likely that a first value interval random number not located in the history random number list is obtained after the step S201 is performed many times, but although the password of the target event can be determined according to the first value interval random number not located in the history random number list, since the step S201 is performed many times, the whole process takes much time, and the step S201 is performed many times, and many system resources are occupied. Thus, the embodiment of FIG. 2 of the present invention does not meet the demand time requirement when the password of the target event needs to be obtained quickly.
Therefore, in the embodiment of the present invention shown in fig. 3, the technician sets the preset number locally in advance, so that when the generation number of the random number in the first value interval, which is located in the first value interval, generated for the target event reaches the preset number, in order to ensure that a password which has not been generated for other events before can be generated for the target event immediately, the process does not return to step S201, and step S303 is executed.
When the generation number of the first value interval random number within the first value interval generated for the target event reaches the preset number, the process may return to step S201 again.
For example, assuming that the preset number of times is 3, when both the first numeric-interval random number within the first numeric interval generated for the target event for the first time and the first numeric-interval random number within the first numeric interval generated for the target event for the second time are in the historical random number list, if the first numeric-interval random number within the first numeric interval generated for the target event for the third time is also in the historical random number list, in order to ensure that a password that has not been generated for another event before can be immediately generated for the target event, the process does not return to step S201, and step S303 is executed.
When the execution times is less than the preset times, in step S201, generating a first value interval random number located in the first value interval;
when the execution times is equal to the preset times, in step S303, a second value interval reference number is generated within a second value interval that does not overlap with the first value interval;
any value in the second value interval is different from any value in the first value interval.
For example, the second value range is 900000-999999; wherein, the second value interval 900000-999999 is not overlapped with the first value interval 100000-899999.
The step can be specifically realized by the following process, including:
11) determining a reference value interval according to the difference value between the maximum value and the minimum value in the second value interval and a preset alternative value;
specifically, two endpoint values of a second value interval are obtained; subtracting the larger end point value from the smaller end point value to obtain a difference value, and then forming a reference value interval taking the preset alternative value and the difference value as the end point value;
the preset candidate value is different from the difference, and the preset candidate value may be greater than the difference or smaller than the difference, which is not limited in the present invention. The present invention is illustrated by taking the example that the preset candidate value is smaller than the difference, but not by limiting the protection scope of the present invention.
For example, the second value interval is 900000-999999, which is not overlapped with the first value interval 000000-899999, and the values of the two end points of the second value interval 900000-999999 are 900000 and 99999999, respectively. Of these two endpoint values, endpoint value 999999 is the larger endpoint value and endpoint value 900000 is the smaller endpoint value. Subtracting the larger end point value 999999 from the smaller end point value 900000 to obtain a difference value 99999, and if the preset candidate value is 0, forming a reference value interval 0-99999 with the preset candidate value 0 and the difference value 99999 as end point values.
12) Selecting one value from the values which are not selected from the reference value interval as an encryption basic value;
generally, in this step, when a value is selected from the reference value range 0 to 99999, the value is selected according to a rule of sequentially selecting the values, for example, when the value is selected from the reference value range 0 to 99999 for the first time, the value 0 is selected from the reference value range 0 to 99999 for the second time, the value 1 is selected as the encryption basic value when the value is selected from the reference value range 0 to 99999 for the second time, the value 2 is selected as the encryption basic value when the value is selected from the reference value range 0 to 99999 for the third time, and so on, that is, when a value is selected from the reference value range 0 to 99999 for the nth time, the selected value is N-1 as the encryption basic value. In this way it can be ensured that the value selected from the reference value interval each time has never been selected during the history.
13) Encrypting the encrypted basic numerical value according to a preset encryption mode to obtain an encrypted numerical value smaller than the difference value;
specifically, the encryption base value may be encrypted according to the following formula;
C=(k1m+k2)mod n;
in the above formula, C is an encrypted numerical value, k1 is a first preset numerical value, k2 is a second preset numerical value, m is an encrypted basic numerical value, n is a third preset numerical value, and mod is a remainder operation symbol.
For example, assuming that the first preset numerical value k1 is 7, the second preset numerical value k2 is 3, the third preset numerical value n is 26, and the encryption basic numerical value selected from the reference numerical value ranges 0 to 99999 is 13, the first preset numerical value 7 is multiplied by the encryption basic numerical value 13 to obtain a numerical value 91, the numerical value 91 is added to the second preset numerical value 3 to obtain a numerical value 94, the numerical value 94 is divided by the third preset numerical value 26 to obtain a remainder 14, and the remainder 14 is used as the encryption numerical value.
14) And adding the encrypted numerical value and the minimum numerical value in the second numerical value interval to obtain a numerical value in the second numerical value interval, and using the numerical value as a reference number of the second numerical value interval.
And 900014 is obtained by adding the encrypted value 14 and the smaller end point value 900000 of the second numerical interval 900000-999999, and the obtained result is used as the reference number of the second numerical interval. Wherein 900014 is located in the second numerical range 900000 ~ 999999.
In step S304, the password of the target event is determined according to the second numerical interval reference number.
For example, the password for the target event is determined from the second numerical interval reference 900014.
Wherein, the second numerical interval reference number can be directly used as the password of the target event. For example, the second numerical interval reference number 900014 is used as the password for the target event.
FIG. 4 is a block diagram illustrating an apparatus for generating a password for a target event in accordance with an exemplary embodiment. Referring to fig. 4, the apparatus includes:
an obtaining module 11, configured to obtain a history random number list when a target event is triggered; the historical random number list comprises random numbers corresponding to the generated passwords;
a generating module 12, configured to generate a target random number that is not in the history random number list within the first value interval;
and the determining module 13 is configured to determine a password of the target event according to the target random number.
In the embodiment of the present invention shown in fig. 4, when a target event is triggered, a history random number list is obtained; the history random number list comprises random numbers corresponding to the generated passwords; generating a target random number which is not positioned in the historical random number list in the first numerical value interval; and determining the password of the target event according to the target random number. According to the method provided by the embodiment of the invention, a large number of different random values do not need to be generated in advance, so that more time is not occupied by the generation of a large number of different random values in advance; and a large amount of random numerical values generated in advance do not need to be stored locally; therefore, the local large storage space is not occupied.
Further, the apparatus further comprises:
and the storage module is used for storing the target random number into the historical random number list.
Wherein the generating module 12 comprises:
the first generating unit is used for generating a first numerical interval random number positioned in the first numerical interval;
the judging unit is used for judging whether the first numerical interval random number is positioned in the historical random number list or not;
a determining unit, configured to determine the first value interval random number as the target random number when the first value interval random number is not located in the history random number list.
Further, the generating module 12 further includes:
the first generating unit is further configured to return to the step of generating a first value interval random number located in the first value interval when the first value interval random number is located in the history random number list until the generated first value interval random number is not located in the history random number list.
Further, the generating module 12 further includes:
the statistical unit is used for counting the generation times of generating the first numerical interval random number in an accumulated mode when the first numerical interval random number is located in the historical random number list;
the comparison unit is used for comparing the generation times with preset times;
the first generating unit is further configured to return to the step of generating a first numerical interval random number located in the first numerical interval when the execution times is less than the preset times;
and the second generating unit is used for generating a second numerical value interval reference number in a second numerical value interval which is not overlapped with the first numerical value interval when the execution times is equal to the preset times, and determining the password of the target event according to the second numerical value interval reference number.
Wherein the second generating unit includes:
the determining subunit is used for determining a reference value interval according to the difference value between the maximum value and the minimum value in the second value interval and a preset alternative value;
a selection subunit, configured to select one of the values that have not been selected from the reference value interval as an encryption base value;
the encryption subunit is used for encrypting the encryption basic value according to a preset encryption mode to obtain an encryption value smaller than the difference value;
and the adding subunit is configured to add the encrypted numerical value to the minimum numerical value in the second numerical value interval to obtain a numerical value located in the second numerical value interval, and use the numerical value as the reference number of the second numerical value interval.
The encryption subunit is specifically configured to encrypt the encryption basic value according to the following formula;
C=(k1m+k2)mod n;
in the above formula, C is the encrypted numerical value, k1 is a first preset numerical value, k2 is a second preset numerical value, m is the encrypted basic numerical value, n is a third preset numerical value, and mod is a remainder operation symbol.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Other embodiments of the invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the invention and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the invention being indicated by the following claims.
It will be understood that the invention is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the invention is limited only by the appended claims.