-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ios.js
161 lines (155 loc) · 4.77 KB
/
index.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import React, { Component } from 'react';
import {
Alert,
AppRegistry,
StyleSheet,
Text,
Clipboard,
View,
ScrollView,
AsyncStorage
} from 'react-native';
import { Card, Button, FormLabel, FormInput } from 'react-native-elements'
const sha1 = require('sha1')
import Storage from 'react-native-storage'
var storage = new Storage({
size: 10,
storageBackend: AsyncStorage,
defaultExpires: null,
enableCache: true
})
storage.sync = {
conKey(params){
let {id, resolve, reject} = params
resolve && resolve('abc')
}
}
global.storage = storage
class Rproject extends React.Component {
constructor(){
super()
storage.load({
key: 'conKey',
id: '1001'
}).then(res => {
this.setState({key: res})
}).catch( err => {
console.log(err)
})
this.state = {
key: '',
flag: '',
p8: '',
p16: '',
p24: ''
}
}
genPassword = (len) => {
let pkey = sha1(this.state.key + 'zznova\'s')
let pwd = sha1(pkey + this.state.flag)
pwd = pwd.replace(/a/g,'@')
pwd = pwd.replace(/1/g,'!')
pwd = pwd.replace(/d/g,'~')
pwd = pwd.replace(/0/g,'^')
return 'Z' + pwd.substring(0, len - 2) + 'z'
}
render() {
return (
<View style={styles.container}>
<Card containerStyle={{marginTop: 40}} title="密码生成器">
<View>
<FormLabel labelStyle={{fontSize: 18}}>密钥</FormLabel>
<FormInput
ref="forminput"
value={this.state.key}
secureTextEntry={true}
textInputRef="password"
onChangeText={(val) => {
this.setState({key: val}, () => {
storage.save({
key: 'conKey',
id: '1001',
data: this.state.key,
expores: null
})
this.setState({
p8: this.genPassword(6),
p16: this.genPassword(12),
p24: this.genPassword(24)
})
})
}} />
<FormLabel labelStyle={{fontSize: 18}}>标识</FormLabel>
<FormInput
ref="forminput"
value={this.state.flag}
placeholder="请输入标识"
onChangeText={(val) => {
this.setState({flag: val}, () => {
this.setState({
p8: this.genPassword(6),
p16: this.genPassword(12),
p24: this.genPassword(24)
})
})
}} />
<View style={styles.line}>
<FormLabel labelStyle={{fontSize: 18}}>6位密码</FormLabel>
<Button
title='复制'
raised
backgroundColor='#397af8'
borderRadius={5}
containerViewStyle={{borderRadius: 5}}
onPress={() => {
Clipboard.setString(this.state.p8)
Alert.alert('复制成功')
}} />
</View>
<FormInput value={this.state.p8} placeholder="8位密码" readonly="readonly" />
<View style={styles.line}>
<FormLabel labelStyle={{fontSize: 18}}>12位密码</FormLabel>
<Button
title='复制'
raised
backgroundColor='#397af8'
borderRadius={5}
containerViewStyle={{borderRadius: 5}}
onPress={() => {
Clipboard.setString(this.state.p16)
Alert.alert('复制成功')
}} />
</View>
<FormInput value={this.state.p16} placeholder="16位密码" readonly="readonly" />
<View style={styles.line}>
<FormLabel labelStyle={{fontSize: 18}}>24位密码</FormLabel>
<Button
title='复制'
raised
backgroundColor='#397af8'
borderRadius={5}
containerViewStyle={{borderRadius: 5}}
onPress={() => {
Clipboard.setString(this.state.p24)
Alert.alert('复制成功')
}} />
</View>
<FormInput value={this.state.p24} placeholder="24位密码" readonly="readonly" />
</View>
</Card>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
width: "100%",
height: "100%",
backgroundColor: '#ddd'
},
line: {
flexDirection: 'row',
marginTop: 10
}
})
AppRegistry.registerComponent('Rproject', () => Rproject)