#import <Foundation/Foundation.h>
#import "Color.h"
#import "ColorData.h"
#import <stdlib.h>
#import "UserRegistration.h"
#import "User.h"
#import "userLogin.h"
#import "ChangePsw.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
#pragma mark --霓虹灯逻辑
#pragma mark --注册逻辑--
UserRegistration *userReg = [[UserRegistration alloc]init];
NSMutableArray *userList = [NSMutableArray array];
userList = [userReg registration];
User *userR = [[User alloc]init];
userR.name = [userList[0] name];
userR.psw = [userList[0] psw];
NSLog(@"注册成功,你的用户名是%@ 密码是%@",userR.name,userR.psw);
#pragma mark ---登录逻辑 --
userLogin *userLog = [[userLogin alloc]init];
NSMutableArray *userList1 = [NSMutableArray array];
userList1 = [userLog login];
User *userL = [[User alloc]init];
userL.name = [userList1[0] name];
userL.psw = [userList1[0] psw];
if ([userR.name isEqualToString:userL.name] != NO) {
if ([userR.psw isEqualToString:userL.psw] != NO) {
NSLog(@"登录成功");
}
else {
NSLog(@"密码出错");
}
}
else {
NSLog(@"用户名出错");
}
#pragma mark -----修改密码逻辑
NSString *newPsw = [[NSString alloc]init];
if ([userR.name isEqualToString:userL.name] != NO){
if ([userR.psw isEqualToString:userL.psw] != NO){
ChangePsw *changePsw = [[ChangePsw alloc]init];
newPsw = [changePsw change];
userL.psw = newPsw;
}
}
}
return 0;
}
#import <Foundation/Foundation.h>
@interface Color : NSObject
@property NSString *name;
- (instancetype)initWithName:(NSString *)name;
@end
#import "Color.h"
@implementation Color
- (instancetype)initWithName:(NSString *)name
{
self = [super init];
if (self) {
_name = name;
}
return self;
}
@end
#import <Foundation/Foundation.h>
@class Color;
@interface ColorData : NSObject
{
Color *red;
Color *black;
Color *green;
}
-(void)loadData;
-(void)chooseColor;
@end
#import "ColorData.h"
#import "Color.h"
@implementation ColorData
-(void)loadData{
NSArray *colorList = [NSArray arrayWithObjects:@"red",@"black",@"green",nil];
red = [[Color alloc]initWithName:colorList[0]];
black = [[Color alloc]initWithName:colorList[1]];
green = [[Color alloc]initWithName:colorList[2]];
}
-(void)chooseColor{
int rand = arc4random()%3;
switch (rand) {
case 0:
NSLog(@"%@",red.name);
break;
case 1:
NSLog(@"%@",black.name);
break;
case 2:
NSLog(@"%@",green.name);
break;
}
}
@end
#import <Foundation/Foundation.h>
@interface User : NSObject
@property NSString *name;
@property NSString *psw;
@end
#import <Foundation/Foundation.h>
@class User;
@interface UserRegistration : NSObject
@property User *user;
@property NSMutableArray *userList;
-(NSMutableArray *)registration;
@end
#import "UserRegistration.h"
#import "User.h"
@implementation UserRegistration
-(NSMutableArray *)registration{
_userList = [NSMutableArray array];
NSLog(@"请输入名字");
NSData *nameData = [[NSFileHandle fileHandleWithStandardInput]availableData];
NSString *nameString1 = [[NSString alloc] initWithData:nameData encoding:NSUTF8StringEncoding];
NSString *nameString = [nameString1 substringToIndex:6];
NSLog(@"%@",nameString);
NSLog(@"请输入6位密码");
NSData *pswData = [[NSFileHandle fileHandleWithStandardInput]availableData];
NSString *pswString1 =[[NSString alloc] initWithData:pswData encoding:NSUTF8StringEncoding];
NSString *pswString =[pswString1 substringToIndex:6];
NSLog(@"%@",pswString);
NSLog(@"请再次输入密码");
NSData *pswData1 = [[NSFileHandle fileHandleWithStandardInput]availableData];
NSString *pswString2 =[[NSString alloc] initWithData:pswData1 encoding:NSUTF8StringEncoding];
NSString *pswString3 =[pswString2 substringToIndex:6];
NSLog(@"%@",pswString3);
if ([pswString isEqualToString:pswString3] != NO) {
_user = [[User alloc]init];
_user.name = nameString;
_user.psw = pswString;
[_userList addObject:_user];
return _userList;
}
else
{ NSLog(@"两次输入的密码不同,请重新注册");exit(0);
return 0;
}
}
@end
#import <Foundation/Foundation.h>
@class User;
@interface userLogin : NSObject
@property User *user;
@property NSMutableArray *userList;
-(NSMutableArray *)login;
@end
#import "userLogin.h"
#import "UserRegistration.h"
#import "User.h"
@implementation userLogin
-(NSMutableArray *)login{
_userList = [NSMutableArray array];
NSLog(@"请输入登录名字");
NSData *nameData = [[NSFileHandle fileHandleWithStandardInput]availableData];
NSString *nameString1 = [[NSString alloc] initWithData:nameData encoding:NSUTF8StringEncoding];
NSString *nameString = [nameString1 substringToIndex:6];
NSLog(@"%@",nameString);
NSLog(@"请输入6位密码");
NSData *pswData = [[NSFileHandle fileHandleWithStandardInput]availableData];
NSString *pswString1 =[[NSString alloc] initWithData:pswData encoding:NSUTF8StringEncoding];
NSString *pswString =[pswString1 substringToIndex:6];
NSLog(@"%@",pswString);
_user = [[User alloc]init];
_user.name = nameString;
_user.psw = pswString;
[_userList addObject:_user];
return _userList;
}
@end
#import <Foundation/Foundation.h>
@interface ChangePsw : NSObject
-(NSString *)change;
@end
#import "ChangePsw.h"
@implementation ChangePsw
-(NSString *)change{
int a =3;
NSLog(@"修改密码");
NSLog(@"请重新输入密码");
while(a){
NSData *newPswData = [[NSFileHandle fileHandleWithStandardInput]availableData];
NSString *newPswString1 =[[NSString alloc] initWithData:newPswData encoding:NSUTF8StringEncoding];
NSString *newPswString =[newPswString1 substringToIndex:6];
NSLog(@"重新输入以确认");
NSData *newPswData1 = [[NSFileHandle fileHandleWithStandardInput]availableData];
NSString *newPswString2 =[[NSString alloc] initWithData:newPswData1 encoding:NSUTF8StringEncoding];
NSString *newPswString3 =[newPswString2 substringToIndex:6];
if ([newPswString isEqualToString:newPswString3]!=NO) {
NSLog(@"密码修改成功");
return newPswString;
}
else
{
a--;
if (a==0) {
NSLog(@"你已经三次输入,请重新登录");
exit(0);
}
NSLog(@"密码修改失败,还有%d次机会,再次输入",a);
}
}
return 0;
}
@end